Skip to content

Instantly share code, notes, and snippets.

@a-mitani
Created July 23, 2020 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-mitani/6d8f27381bd48004d2462cf98a6c6a12 to your computer and use it in GitHub Desktop.
Save a-mitani/6d8f27381bd48004d2462cf98a6c6a12 to your computer and use it in GitHub Desktop.
用意したトイデータを学習&予測
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
lr = LinearRegression().fit(X_train, y_train)
y_pred_lr = lr.predict(X_test)
rf = RandomForestRegressor().fit(X_train, y_train)
y_pred_rf = rf.predict(X_test)
# 精度評価
fig, ax = plt.subplots()
ax.plot([-6, 6], [-6, 6])
ax.set_xlim([-6, 6])
ax.scatter(y_test, y_pred_lr, alpha=0.5, label='Linear Regression')
ax.scatter(y_test, y_pred_rf, alpha=0.5, label='Random Forest')
ax.legend()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment