-
-
Save amankharwal/d1941945910c97464849bed1ccc6c834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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