Skip to content

Instantly share code, notes, and snippets.

@Manikant92
Created September 5, 2018 05:17
Show Gist options
  • Save Manikant92/a58ff95a6f31456b22a49d0d8aed9d30 to your computer and use it in GitHub Desktop.
Save Manikant92/a58ff95a6f31456b22a49d0d8aed9d30 to your computer and use it in GitHub Desktop.
#follow same process which was discussed before converting lists into dictionary then dataframe
new_dictionary = {'X': new_x, 'y':new_y}
new_df = pd.DataFrame(new_dictionary)
#split the data of 10 rows into 80% train set and 20% test set
new_X_train, new_X_test, new_y_train, new_y_test = train_test_split(new_df[['X']],new_df.y,test_size=0.2, random_state=5)
#fit to find the best fit
lr.fit(new_X_train, new_y_train)
#print slope
print(lr.coef_[0])
#output: 2.27600849
print(lr.intercept_)
#output: 7.6284501061571159
new_y_pred = lr.predict(new_X_test)
metrics.r2_score(new_y_test, new_y_pred)*100
#output: 90.480057427405569 - accuracy and our model confidence score
print(new_y_pred)
# [ 32.66454352 23.56050955]- predicted
#actual: [34, 25]
print(new_X_test)
X : 11, 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment