Files
2019-05-07 11:33:15 +08:00

13 lines
445 B
Python

import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
df = pd.read_csv(open("C:\\Users\\wenyan\\PycharmProjects\\Sklearn\\data\\房源.csv"))
fig, ax = plt.subplots()
ax.scatter(df["room"], df["total_price"])
lr = linear_model.LinearRegression(normalize=True)
X = df["room"].values.reshape(len(df["room"]), 1)
Y = df["total_price"].values.ravel()
lr.fit(X, Y)
ax.plot([1, 2, 3], lr.predict([[1], [2], [3]]), 'r')