Kaggle competition: Atividade_3_PMR3508
<SOS> metric: rmsle Kaggle data source: atividade_3_pmr3508<train_model>
from sklearn.metrics import make_scorer
import pandas as pd
import math
import scipy
from scipy.stats import pearsonr
import numpy as np
import matplotlib.pyplot as plt
import sklearn
from sklearn import tree
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.ensemble import BaggingRegressor
from sklearn.ensemble import AdaBoostRegressor
from sklearn.metrics import accuracy_score
from sklearn.model_selection import cross_val_score
from sklearn import linear_model
X_train, X_test,y_train, y_test = train_test_split(train,y['Survived'],test_size=0.2,random_state=42)
 clf = LogisticRegression(max_iter=1000)
 for i in range(1,train.shape[1]+1):
model = SelectKBest(chi2,i)
 X_X_train = model.fit_transform(X_train,y_train)
 X_X_test = model.transform(X_test)
 clf.fit(X_X_train,y_train)
 print('Accuracy score for ', i, ' features is ',accuracy_score(y_test,clf.predict(X_X_test)))
<define_search_model>
train = pd.read_csv(".. /input/california/train.csv" )
logreg_clf = LogisticRegression(max_iter=1000)
 rf_clf = RandomForestClassifier()
dt_clf = DecisionTreeClassifier()
xgb = XGBClassifier()
svm = SVC()<predict_on_test>
train = pd.read_csv(".. /input/california/train.csv")
 vale_silicio = {'latitude':37.84, 'longitude':-122.05}
train['dist_vs'] =(((train['longitude']-vale_silicio['longitude'])**2+(train['latitude']-vale_silicio['latitude'])**2)**(1/2))
beverly_hills = {'latitude':33.933333, 'longitude':-118.4}
train['dist_bh'] =(((train['longitude']-beverly_hills['longitude'])**2+(train['latitude']-beverly_hills['latitude'])**2)**(1/2))
corona_del_mar = {'latitude':33.5978595,'longitude':-117.8730142}
train['dist_cdm'] =(((train['longitude']-corona_del_mar['longitude'])**2+(train['latitude']-corona_del_mar['latitude'])**2)**(1/2))
montecito = {'latitude':34.43666 ,'longitude':-119.63208}
train['dist_mt'] =(((train['longitude']-montecito['longitude'])**2+(train['latitude']-montecito['latitude'])**2)**(1/2))
atherton = {'latitude':37.458611,'longitude': -122.2}
train['dist_at'] =(((train['longitude']-atherton['longitude'])**2+(train['latitude']-atherton['latitude'])**2)**(1/2))
wdside = {'latitude':37.420833, 'longitude':-122.259722}
train['dist_wd'] =(((train['longitude']-wdside['longitude'])**2+(train['latitude']-wdside['latitude'])**2)**(1/2))
hdhills = {'latitude': 34.1675, 'longitude':-118.660833}
train['dist_hh'] =(((train['longitude']-hdhills['longitude'])**2+(train['latitude']-hdhills['latitude'])**2)**(1/2))
latos = {'latitude':37.368056, 'longitude':-122.0975}
train['dist_lal'] =(((train['longitude']-latos['longitude'])**2+(train['latitude']-latos['latitude'])**2)**(1/2))
bvde = {'latitude':37.872778, 'longitude':-122.464444}
train['dist_bvd'] =(((train['longitude']-bvde['longitude'])**2+(train['latitude']-bvde['latitude'])**2)**(1/2))
stm = {'latitude':34.021944, 'longitude': -118.481389}
train['dist_stm'] =(((train['longitude']-stm['longitude'])**2+(train['latitude']-stm['latitude'])**2)**(1/2))
ross = {'latitude':37.9625,'longitude': -122.555}
train['dist_ros'] =(((train['longitude']-ross['longitude'])**2+(train['latitude']-ross['latitude'])**2)**(1/2))
fremont = {'latitude':37.548333, 'longitude':-121.988611}
train['dist_frm'] =(((train['longitude']-fremont['longitude'])**2+(train['latitude']-fremont['latitude'])**2)**(1/2))
hbr = {'latitude':37.560278, 'longitude': -122.356389}
train['dist_hbr'] =(((train['longitude']-hbr['longitude'])**2+(train['latitude']-hbr['latitude'])**2)**(1/2))
npb = {'latitude':33.616667, 'longitude':-117.8975}
train['dist_npb'] =(((train['longitude']-npb['longitude'])**2+(train['latitude']-npb['latitude'])**2)**(1/2))
plh = {'latitude':33.5901144,'longitude':-117.8445537}
train['dist_plh'] =(((train['longitude']-plh['longitude'])**2+(train['latitude']-plh['latitude'])**2)**(1/2))
blt = {'latitude': 33.610278, 'longitude': -114.596389}
train['dist_blt'] =(((train['longitude']-blt['longitude'])**2+(train['latitude']-blt['latitude'])**2)**(1/2))
tnp = {'latitude':34.138333, 'longitude': -116.0725}
train['dist_tnp'] =(((train['longitude']-tnp['longitude'])**2+(train['latitude']-tnp['latitude'])**2)**(1/2))
avn = {'latitude':35.209167, 'longitude': -118.828333}
train['dist_avn'] =(((train['longitude']-avn['longitude'])**2+(train['latitude']-avn['latitude'])**2)**(1/2))
wdl = {'latitude':36.416389, 'longitude':-119.099444}
train['dist_wdl'] =(((train['longitude']-wdl['longitude'])**2+(train['latitude']-wdl['latitude'])**2)**(1/2))
plr = {'latitude':36.611667, 'longitude':-119.526944}
train['dist_plr'] =(((train['longitude']-plr['longitude'])**2+(train['latitude']-plr['latitude'])**2)**(1/2))
ccc = {'latitude': 35.125833, 'longitude': -117.985833}
train['dist_ccc'] =(((train['longitude']-ccc['longitude'])**2+(train['latitude']-ccc['latitude'])**2)**(1/2))
fmv = {'latitude':36.301111, 'longitude': -119.2075}
train['dist_fmv'] =(((train['longitude']-fmv['longitude'])**2+(train['latitude']-fmv['latitude'])**2)**(1/2))
lds = {'latitude':36.2, 'longitude':-119.083333}
train['dist_lds'] =(((train['longitude']-lds['longitude'])**2+(train['latitude']-lds['latitude'])**2)**(1/2))
wsc = {'latitude':35.594167, 'longitude':-119.340833}
train['dist_wsc'] =(((train['longitude']-wsc['longitude'])**2+(train['latitude']-wsc['latitude'])**2)**(1/2))
ccn = {'latitude':36.098056, 'longitude':-119.560278}
train['dist_ccn'] =(((train['longitude']-ccn['longitude'])**2+(train['latitude']-ccn['latitude'])**2)**(1/2))
a = train['median_house_value']
train = train.drop(columns = ['median_house_value'])
 train['median_house_value'] = a
train.head()
logreg_clf.fit(X_train,y_train)
 rf_clf.fit(X_train,y_train)
 dt_clf.fit(X_train,y_train)
 xgb.fit(X_train,y_train)
 svm.fit(X_train,y_train)
 logreg_pred = logreg_clf.predict(X_test)
 rf_pred = rf_clf.predict(X_test)
 dt_pred = dt_clf.predict(X_test)
 xgb_pred = xgb.predict(X_test)
 svm_pred = svm.predict(X_test)
 average_pred =(logreg_pred + rf_pred + dt_pred + xgb_pred + svm_pred)//5
acc = accuracy_score(y_test, average_pred)
 print('Accuracy score simple averaging ', acc*100 )<train_model>
test = pd.read_csv(".. /input/california/test.csv" )
voting_clf = VotingClassifier(estimators=[('LogReg',logreg_clf), 
('RandomForest',rf_clf), 
('DecisionTree',dt_clf), 
('XGBoost',xgb), 
('SVM',svm)], voting='hard')
 voting_clf.fit(X_train,y_train)
 voting_pred = voting_clf.predict(X_test)
 acc = accuracy_score(y_test,voting_pred)
 print('Accuracy of voting classifier(hard)',acc*100)
<predict_on_test>
test = pd.read_csv(".. /input/california/test.csv")
 vale_silicio = {'latitude':37.84, 'longitude':-122.05}
test['dist_vs'] =(((test['longitude']-vale_silicio['longitude'])**2+(test['latitude']-vale_silicio['latitude'])**2)**(1/2))
beverly_hills = {'latitude':33.933333, 'longitude':-118.4}
test['dist_bh'] =(((test['longitude']-beverly_hills['longitude'])**2+(test['latitude']-beverly_hills['latitude'])**2)**(1/2))
corona_del_mar = {'latitude':33.5978595,'longitude':-117.8730142}
test['dist_cdm'] =(((test['longitude']-corona_del_mar['longitude'])**2+(test['latitude']-corona_del_mar['latitude'])**2)**(1/2))
montecito = {'latitude':34.43666 ,'longitude':-119.63208}
test['dist_mt'] =(((test['longitude']-montecito['longitude'])**2+(test['latitude']-montecito['latitude'])**2)**(1/2))
atherton = {'latitude':37.458611,'longitude': -122.2}
test['dist_at'] =(((test['longitude']-atherton['longitude'])**2+(test['latitude']-atherton['latitude'])**2)**(1/2))
wdside = {'latitude':37.420833, 'longitude':-122.259722}
test['dist_wd'] =(((test['longitude']-wdside['longitude'])**2+(test['latitude']-wdside['latitude'])**2)**(1/2))
hdhills = {'latitude': 34.1675, 'longitude':-118.660833}
test['dist_hh'] =(((test['longitude']-hdhills['longitude'])**2+(test['latitude']-hdhills['latitude'])**2)**(1/2))
latos = {'latitude':37.368056, 'longitude':-122.0975}
test['dist_lal'] =(((test['longitude']-latos['longitude'])**2+(test['latitude']-latos['latitude'])**2)**(1/2))
bvde = {'latitude':37.872778, 'longitude':-122.464444}
test['dist_bvd'] =(((test['longitude']-bvde['longitude'])**2+(test['latitude']-bvde['latitude'])**2)**(1/2))
stm = {'latitude':34.021944, 'longitude': -118.481389}
test['dist_stm'] =(((test['longitude']-stm['longitude'])**2+(test['latitude']-stm['latitude'])**2)**(1/2))
ross = {'latitude':37.9625,'longitude': -122.555}
test['dist_ros'] =(((test['longitude']-ross['longitude'])**2+(test['latitude']-ross['latitude'])**2)**(1/2))
fremont = {'latitude':37.548333, 'longitude':-121.988611}
test['dist_frm'] =(((test['longitude']-fremont['longitude'])**2+(test['latitude']-fremont['latitude'])**2)**(1/2))
hbr = {'latitude':37.560278, 'longitude': -122.356389}
test['dist_hbr'] =(((test['longitude']-hbr['longitude'])**2+(test['latitude']-hbr['latitude'])**2)**(1/2))
npb = {'latitude':33.616667, 'longitude':-117.8975}
test['dist_npb'] =(((test['longitude']-npb['longitude'])**2+(test['latitude']-npb['latitude'])**2)**(1/2))
plh = {'latitude':33.5901144,'longitude':-117.8445537}
test['dist_plh'] =(((test['longitude']-plh['longitude'])**2+(test['latitude']-plh['latitude'])**2)**(1/2))
blt = {'latitude': 33.610278, 'longitude': -114.596389}
test['dist_blt'] =(((test['longitude']-blt['longitude'])**2+(test['latitude']-blt['latitude'])**2)**(1/2))
tnp = {'latitude':34.138333, 'longitude': -116.0725}
test['dist_tnp'] =(((test['longitude']-tnp['longitude'])**2+(test['latitude']-tnp['latitude'])**2)**(1/2))
avn = {'latitude':35.209167, 'longitude': -118.828333}
test['dist_avn'] =(((test['longitude']-avn['longitude'])**2+(test['latitude']-avn['latitude'])**2)**(1/2))
wdl = {'latitude':36.416389, 'longitude':-119.099444}
test['dist_wdl'] =(((test['longitude']-wdl['longitude'])**2+(test['latitude']-wdl['latitude'])**2)**(1/2))
plr = {'latitude':36.611667, 'longitude':-119.526944}
test['dist_plr'] =(((test['longitude']-plr['longitude'])**2+(test['latitude']-plr['latitude'])**2)**(1/2))
ccc = {'latitude': 35.125833, 'longitude': -117.985833}
test['dist_ccc'] =(((test['longitude']-ccc['longitude'])**2+(test['latitude']-ccc['latitude'])**2)**(1/2))
fmv = {'latitude':36.301111, 'longitude': -119.2075}
test['dist_fmv'] =(((test['longitude']-fmv['longitude'])**2+(test['latitude']-fmv['latitude'])**2)**(1/2))
lds = {'latitude':36.2, 'longitude':-119.083333}
test['dist_lds'] =(((test['longitude']-lds['longitude'])**2+(test['latitude']-lds['latitude'])**2)**(1/2))
wsc = {'latitude':35.594167, 'longitude':-119.340833}
test['dist_wsc'] =(((test['longitude']-wsc['longitude'])**2+(test['latitude']-wsc['latitude'])**2)**(1/2))
ccn = {'latitude':36.098056, 'longitude':-119.560278}
test['dist_ccn'] =(((test['longitude']-ccn['longitude'])**2+(test['latitude']-ccn['latitude'])**2)**(1/2))
test.head()
voting_clf2 = VotingClassifier(estimators=[('LogReg',logreg_clf), 
('RandomForest',rf_clf), 
('DecisionTree',dt_clf), 
('XGBoost',xgb)], voting='soft')
 voting_clf2.fit(X_train,y_train)
 voting_pred = voting_clf2.predict(X_test)
 acc = accuracy_score(y_test,voting_pred)
 print('Accuracy of voting classifier(soft)',acc*100 )<save_to_csv>
def RMSLE(Y, Ypred):
n = len(Y)
 soma = 0
Y = np.array(Y)
 for i in range(len(Y)) :
soma +=(math.log(abs(Ypred[i])+ 1)- math.log(Y[i] + 1)) **2
return math.sqrt(soma / n)
 scorer_rmsle = make_scorer(RMSLE )
voting_clf2.fit(train,y['Survived'])
 y_pred=voting_clf.predict(test)
 submit = pd.concat([pd.DataFrame(data=test_passengerId,columns=['PassengerId']),pd.DataFrame(data=y_pred, columns=['Survived'])],axis=1)
 submit.to_csv('gender_submission.csv',index=False)
<import_modules>
Xtrain = train.iloc[:,1:34]
Ytrain = train.median_house_value
Xtest = test.iloc[:,1:34]
import pandas as pd
import numpy as np
import seaborn as sns
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.multioutput import MultiOutputRegressor
from sklearn.metrics import mean_absolute_error<load_from_csv>
reglin = linear_model.LinearRegression()
reglin.fit(Xtrain, Ytrain)
 total = 0
c_val = 10
scores = cross_val_score(reglin,Xtrain,Ytrain, cv = c_val,scoring = scorer_rmsle)
 total = 0
for j in scores:
total += j
acuracia_esperada = total/c_val
print(acuracia_esperada)
train = pd.read_csv('.. /input/titanic/train.csv')
 test = pd.read_csv('.. /input/titanic/test.csv')
 df=pd.concat([train,test] ).reset_index()<filter>
Ytest_pred1 = reglin.predict(Xtest)
 for i in Ytest_pred1:
if i < 0:
Ytest_pred1 = abs(Ytest_pred1 )
df[df['Embarked'].isnull() ]<feature_engineering>
result1 = np.vstack(( test['Id'], Ytest_pred1)).T.astype(int)
 x1 = ["Id","median_house_value"]
Resultado1 = pd.DataFrame(columns = x1, data = result1 )
df['Embarked']=df['Embarked'].fillna('S' )<filter>
ridge = linear_model.Ridge()
ridge.fit(Xtrain,Ytrain)
 total = 0
c_val = 10
scores = cross_val_score(ridge,Xtrain,Ytrain, cv = c_val,scoring = scorer_rmsle)
 total = 0
for j in scores:
total += j
acuracia_esperada = total/c_val
print(acuracia_esperada )
df[df['Fare'].isnull() ]<feature_engineering>
Ytest_pred2 = ridge.predict(Xtest)
 Ytest_pred2 = abs(Ytest_pred2 )
t=df[(df['Embarked']=='S')&(df['Pclass']==3)]['Fare'].median()
df['Fare']=df['Fare'].fillna(t )<prepare_x_and_y>
result2 = np.vstack(( test['Id'], Ytest_pred2)).T.astype(int)
 x2 = ["Id","median_house_value"]
Resultado2 = pd.DataFrame(columns = x2, data = result2 )
Y, X = dmatrices('Survived ~ Pclass+Sex+Fare', df, return_type='dataframe')
 vif = pd.DataFrame()
vif["VIF Factor"] = [variance_inflation_factor(X.values, i)for i in range(X.shape[1])]
vif["features"] = X.columns
vif<categorify>
lasso = linear_model.Lasso()
lasso.fit(Xtrain, Ytrain)
 total = 0
c_val = 10
scores = cross_val_score(lasso,Xtrain,Ytrain, cv = c_val,scoring = scorer_rmsle)
 total = 0
for j in scores:
total += j
acuracia_esperada = total/c_val
print(acuracia_esperada )
y = train["Survived"]
h=train[(train['Embarked']=='S')&(train['Pclass']==3)]['Fare'].median()
train['Fare']=train['Fare'].fillna(h)
 l=test[(test['Embarked']=='S')&(test['Pclass']==3)]['Fare'].median()
test['Fare']=test['Fare'].fillna(l)
 features = ["Pclass", "Sex", "Fare"]
X = pd.get_dummies(train[features])
 X_test = pd.get_dummies(test[features])
 model = RandomForestClassifier(n_estimators=1000, max_depth=5, random_state=1)
 model.fit(X, y)
 predictions = model.predict(X_test)
 output = pd.DataFrame({'PassengerId': test.PassengerId, 'Survived': predictions})
 output.to_csv('final_submission.csv', index=False )<load_from_csv>
Ytest_pred3 = ridge.predict(Xtest)
 Ytest_pred3 = abs(Ytest_pred3 )
train_df = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/train.csv')
 test_df = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/test.csv' )<concatenate>
result3 = np.vstack(( test['Id'], Ytest_pred3)).T.astype(int)
 x3 = ["Id","median_house_value"]
Resultado3 = pd.DataFrame(columns = x3, data = result3 )
data = pd.concat([train_df, test_df], sort=False)
 data = data.reset_index(drop=True)
 data.head()<filter>
arvore = tree.DecisionTreeRegressor()
arvore.fit(Xtrain,Ytrain)
 scores = cross_val_score(arvore,Xtrain,Ytrain, cv = c_val,scoring = scorer_rmsle)
 total = 0
for j in scores:
total += j
acuracia_esperada = total/c_val
print(acuracia_esperada )
nans=pd.isnull(data ).sum()
nans[nans>0]<data_type_conversions>
Ytest_pred4 = arvore.predict(Xtest)
data['MSZoning'] = data['MSZoning'].fillna(data['MSZoning'].mode() [0])
 data['Utilities'] = data['Utilities'].fillna(data['Utilities'].mode() [0])
 data['Exterior1st'] = data['Exterior1st'].fillna(data['Exterior1st'].mode() [0])
 data['Exterior2nd'] = data['Exterior2nd'].fillna(data['Exterior2nd'].mode() [0])
 data["BsmtFinSF1"] = data["BsmtFinSF1"].fillna(0)
 data["BsmtFinSF2"] = data["BsmtFinSF2"].fillna(0)
 data["BsmtUnfSF"] = data["BsmtUnfSF"].fillna(0)
 data["TotalBsmtSF"] = data["TotalBsmtSF"].fillna(0)
 data["BsmtFullBath"] = data["BsmtFullBath"].fillna(0)
 data["BsmtHalfBath"] = data["BsmtHalfBath"].fillna(0)
 data["BsmtQual"] = data["BsmtQual"].fillna("None")
 data["BsmtCond"] = data["BsmtCond"].fillna("None")
 data["BsmtExposure"] = data["BsmtExposure"].fillna("None")
 data["BsmtFinType1"] = data["BsmtFinType1"].fillna("None")
 data["BsmtFinType2"] = data["BsmtFinType2"].fillna("None")
 data['KitchenQual'] = data['KitchenQual'].fillna(data['KitchenQual'].mode() [0])
 data["Functional"] = data["Functional"].fillna("Typ")
 data["FireplaceQu"] = data["FireplaceQu"].fillna("None")
 data["GarageType"] = data["GarageType"].fillna("None")
 data["GarageYrBlt"] = data["GarageYrBlt"].fillna(0)
 data["GarageFinish"] = data["GarageFinish"].fillna("None")
 data["GarageCars"] = data["GarageCars"].fillna(0)
 data["GarageArea"] = data["GarageArea"].fillna(0)
 data["GarageQual"] = data["GarageQual"].fillna("None")
 data["GarageCond"] = data["GarageCond"].fillna("None")
 data["PoolQC"] = data["PoolQC"].fillna("None")
 data["Fence"] = data["Fence"].fillna("None")
 data["MiscFeature"] = data["MiscFeature"].fillna("None")
 data['SaleType'] = data['SaleType'].fillna(data['SaleType'].mode() [0])
 data['LotFrontage'].interpolate(method='linear',inplace=True)
 data["Electrical"] = data.groupby("YearBuilt")['Electrical'].transform(lambda x: x.fillna(x.mode() [0]))
data["Alley"] = data["Alley"].fillna("None")
 data["MasVnrType"] = data["MasVnrType"].fillna("None")
 data["MasVnrArea"] = data["MasVnrArea"].fillna(0 )<filter>
result4 = np.vstack(( test['Id'], Ytest_pred4)).T.astype(int)
 x4 = ["Id","median_house_value"]
Resultado4 = pd.DataFrame(columns = x4, data = result4 )
nans=pd.isnull(data ).sum()
nans[nans>0]<set_options>
bot = BaggingRegressor(n_estimators = 200)
 bot.fit(Xtrain,Ytrain)
 total = 0
c_val = 10
scores = cross_val_score(bot,Xtrain,Ytrain, cv = c_val,scoring = scorer_rmsle)
 total = 0
for j in scores:
total += j
acuracia_esperada = total/c_val
print(acuracia_esperada )
warnings.filterwarnings(action='ignore' )<categorify>
Ytest_pred5 = bot.predict(Xtest)
_list = []
for col in data.columns:
if type(data[col][0])== type('str'):
_list.append(col)
 le = preprocessing.LabelEncoder()
for li in _list:
le.fit(list(set(data[li])))
 data[li] = le.transform(data[li] )<prepare_x_and_y>
result5 = np.vstack(( test['Id'], Ytest_pred5)).T.astype(int)
 x5 = ["Id","median_house_value"]
Resultado5 = pd.DataFrame(columns = x5, data = result5 )
train, test = data[:len(train_df)], data[len(train_df):]
X = train.drop(columns=['SalePrice', 'Id'])
 y = train['SalePrice']
test = test.drop(columns=['SalePrice', 'Id'] )<choose_model_class>
rdf = RandomForestRegressor(n_estimators = 200, max_features = 'log2', min_samples_leaf = 1)
 rdf.fit(Xtrain, Ytrain)
 total = 0
c_val = 10
scores = cross_val_score(rdf,Xtrain,Ytrain, cv = c_val,scoring = scorer_rmsle)
 total = 0
for j in scores:
total += j
acuracia_esperada = total/c_val
print(acuracia_esperada )
kfold = KFold(n_splits=10, random_state = 77, shuffle = True )<choose_model_class>
Ytest_pred6 = rdf.predict(Xtest)
params = {
'task' : 'train',
'objective' : 'regression',
'subsample' : 0.8,
'max_depth' : 7
}
param_grid = {
'learning_rate': [0.1],
'feature_fraction' : [0.5, 0.8],
'num_leaves':[31, 63, 127]
}
lgbm_model = lgbm.LGBMRegressor(**params, verbose=-1)
 lgbm_grid = GridSearchCV(lgbm_model,
param_grid,
cv=kfold,
scoring='neg_mean_squared_error',
return_train_score=True)
 lgbm_grid.fit(X, y)
 r2_score(lgbm_grid.predict(X), y )<find_best_params>
result6 = np.vstack(( test['Id'], Ytest_pred6)).T.astype(int)
 x6 = ["Id","median_house_value"]
Resultado = pd.DataFrame(columns = x6, data = result6)
 Resultado.to_csv("resultados_rdf.csv", index = False )
lgbm_grid.best_estimator_<train_on_grid>
etr = ExtraTreesRegressor(n_estimators = 200)
 etr.fit(Xtrain,Ytrain)
 total = 0
c_val = 10
scores = cross_val_score(etr,Xtrain,Ytrain, cv = c_val,scoring = scorer_rmsle)
 total = 0
for j in scores:
total += j
acuracia_esperada = total/c_val
print(acuracia_esperada )
param_grid = {
'learning_rate': [0.1],
'subsample' : [0.5, 0.8, 1.0],
'max_depth':[4, 5, 8]
}
xgb_model = xgb.XGBRegressor()
xgb_grid = GridSearchCV(xgb_model,
param_grid,
cv=kfold,
scoring='neg_mean_squared_error')
 xgb_grid.fit(X, y)
 r2_score(xgb_grid.predict(X), y )<find_best_params>
Ytest_pred7 = rdf.predict(Xtest)
xgb_grid.best_estimator_<train_model>
result7 = np.vstack(( test['Id'], Ytest_pred7)).T.astype(int)
 x7 = ["Id","median_house_value"]
Resultado = pd.DataFrame(columns = x7, data = result7 )