rjmessibarca.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:challenges 作者: py-study-group 项目源码 文件源码
def regression_murder(year):  # applies linear regression on murder rates
    murder = pd.DataFrame()
    dates = crime_rate_df.index.values.tolist()
    murder['label'] = crime_rate_df['Murder and\nnonnegligent \nmanslaughter']
    prediction_size = int(0.1 * len(murder))

    X = np.array(dates)
    y = np.array(murder['label'])
    y.reshape((len(X), 1))
    y_train = y[:-prediction_size]
    X_train = X[:-prediction_size]
    clf = LinearRegression()

    clf.fit(X_train.reshape(-1, 1), y_train)
    regression_line = [clf.predict(X_train[i].reshape(1, -1)) for i in range(len(X_train))]
    print(clf.predict(year))
    plt.scatter(X_train, y_train)
    plt.plot(X_train, regression_line)
    plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号