

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Helpful for practical guide and experiment
Typology: Study Guides, Projects, Research
1 / 2
This page cannot be seen from the preview
Don't miss anything!


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)