forked from naman05rathi/HR_PriceAppraisal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FINALrandom.py
30 lines (22 loc) · 1.01 KB
/
FINALrandom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pandas as pd
from pandas import DataFrame
from sklearn.cross_validation import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import MinMaxScaler
import numpy as np
from numpy import ndarray
import csv
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
from sklearn import cross_validation, metrics
df = pd.read_csv("solution.csv")
scaler = MinMaxScaler()
df[['BHK', 'AREA', 'YEARS', 'BATH', 'FLOOR', 'LAT', 'LONG', 'MD_AIRPORT']] = scaler.fit_transform(df[['BHK', 'AREA', 'YEARS', 'BATH', 'FLOOR', 'LAT', 'LONG', 'MD_AIRPORT']])
dfx = df[['BHK', 'AREA', 'YEARS', 'BATH', 'FLOOR', 'LAT', 'LONG', 'MD_AIRPORT']].copy()
dfy = df[['PRICE']].copy()
x_train, x_test, y_train, y_test = train_test_split(dfx,dfy,test_size = 0.3)
model = RandomForestRegressor(n_estimators = 100, max_features = 'sqrt')
model.fit(x_train, y_train.values.ravel())
ans=model.predict(x_test)
normal_ytest = y_test.as_matrix()
result_r2 = r2_score(normal_ytest, ans)