Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created February 15, 2021 07:20
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 amankharwal/d1941945910c97464849bed1ccc6c834 to your computer and use it in GitHub Desktop.
Save amankharwal/d1941945910c97464849bed1ccc6c834 to your computer and use it in GitHub Desktop.
import pandas as pd
from sklearn.model_selection import train_test_split
data = pd.read_csv("melb.csv")
columns = ["Rooms", "Distance", "Landsize", "BuildingArea", "YearBuilt"]
x = data[columns]
y = data.Price
x_train, x_test, y_train, y_test = train_test_split(x, y)
from sklearn.ensemble import RandomForestRegressor
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import Imputer
pipe = make_pipeline(Imputer(), RandomForestRegressor())
pipe.fit(x_train, y_train)
predictions = pipe.predict(x_test)
imputer = Imputer()
model = RandomForestRegressor()
imputed_x_train = imputer.fit_transform(x_train)
imputed_x_test = imputer.transform(x_test)
model.fit(imputed_x_train, y_train)
predictions = model.predict(imputed_x_test)
print(predictions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment