Simple Linear Regression Step 1: Data Preprocessing
import pandas as pd import numpy as np import matplotlib.pyplot as plt dataset = pd.read_csv("studentscores.csv") X = dataset.iloc[ : , : 1 ].values Y = dataset.iloc[ : , 1 ].values from sklearn.cross_validation import train_test_split X_train, X_test, Y_train, Y_test = train_test_split( X, Y, test_size = 1/4, random_state = 0)Step 2: Fitting Simple Linear Regression Model to the training set
from sklearn.linear_model import LinearRegression regressor = LinearRegression() regressor = regressor.fit(X_train, Y_train)
# Step 3: Predecting the Result
Y_pred = regressor.predict(X_test)
# Step 4: Visualization
## Visualising the Training results
plt.scatter(X_train , Y_train, color = "red") plt.plot(X_train , regressor.predict(X_train), color ="blue")
## Visualizing the test results
plt.scatter(X_test , Y_test, color = "red") plt.plot(X_test , regressor.predict(X_test), color ="blue")
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/42277.html
阅读 3107·2021-10-12 10:11
阅读 1818·2021-08-16 10:59
阅读 2829·2019-08-30 15:55
阅读 1202·2019-08-30 14:19
阅读 2008·2019-08-29 17:03
阅读 2439·2019-08-29 16:28
阅读 3192·2019-08-26 13:47
阅读 2860·2019-08-26 13:36