| import pandas as pd |
| import matplotlib.pyplot as plt |
| from matplotlib.font_manager import FontProperties |
| from sklearn.model_selection import train_test_split |
| from sklearn.linear_model import LinearRegression |
| %matplotlib inline |
| font = FontProperties(fname='/Library/Fonts/Heiti.ttc') |
| df = pd.read_csv('housing-data.txt', sep='\s+', header=0) |
| X = df.iloc[:, :-1].values |
| y = df['MEDV'].values |
| |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) |
| lr = LinearRegression() |
| |
| lr.fit(X_train, y_train) |
| |
| y_train_predict = lr.predict(X_train) |
| |
| y_test_predict = lr.predict(X_test) |