Physics practical report, Study Guides, Projects, Research of Physics

Helpful for practical guide and experiment

Typology: Study Guides, Projects, Research

2022/2023

Uploaded on 07/31/2024

teboho-masilo
teboho-masilo 🇿🇦

3 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Activate data management: importpandasaspd
Upload data: fromgoogle.colabimportfiles
upload=files.upload()
To see table: importio
df2=pd.read_csv(io.BytesIO(upload['dat.csv']))
print(df2)
Inspect data: df2.shape
df2.head()
Assign independent and dependent variables:
X=df2['Distance'].values.reshape(-1,1)
Y=df2['Difference'].values.reshape(-1,1)
Import Stats packages:
importmatplotlib.pyplotasplt
importseabornassns
importnumpyasnp
importpandasaspd
fromsklearn.model_selectionimporttrain_test_split
fromsklearn.linear_modelimportLinearRegression
fromsklearn.preprocessingimportMinMaxScaler
fromsklearn.metricsimportr2_score
importstatsmodels.apiassm
importscipy.statsasstats
Create object class for graph:
model=LinearRegression()
Perform the linear regression:
model.fit(X,Y)
Y_pred=linear_regressor.predict(X)
Add regression line and view your plot!
plt.scatter(X,Y)
pf2

Partial preview of the text

Download Physics practical report and more Study Guides, Projects, Research Physics in PDF only on Docsity!

Activate data management: import pandas as pd Upload data: from google.colab import files upload=files.upload() To see table: import io df2 = pd.read_csv(io.BytesIO(upload['dat.csv'])) print(df2) Inspect data: df2.shape df2.head() Assign independent and dependent variables: X = df2['Distance'].values.reshape(-1, 1 ) Y = df2['Difference'].values.reshape(-1, 1 ) Import Stats packages: import matplotlib.pyplot as plt import seaborn as sns import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LinearRegression from sklearn.preprocessing import MinMaxScaler from sklearn.metrics import r2_score import statsmodels.api as sm import scipy.stats as stats Create object class for graph: model = LinearRegression() Perform the linear regression: model.fit(X, Y) Y_pred = linear_regressor.predict(X) Add regression line and view your plot! plt.scatter(X, Y)

plt.plot(X, Y_pred, color='red') plt.show() Regression equation (Y = mx+c)???? and correlation coefficient? m = slope x = intercept to find the slope: print('slope:', model.coef_) to find the intercept: print('intercept:', model.intercept_) Correlation coeffient: pearson_coef= stats.pearsonr(df2['Afstand'], df2['Verskil']) print("The Pearson Correlation Coefficient is", pearson_coef) Coefficient of determination: r_sq = model.score(X, Y) print('coefficient of determination:', r_sq)