日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kaggle House_Price_XGBoost

發布時間:2025/4/5 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kaggle House_Price_XGBoost 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

kaggle House_Price_final

代碼

import numpy as np import pandas as pd from sklearn.ensemble import RandomForestRegressor from sklearn.metrics import mean_absolute_error from sklearn.model_selection import train_test_split from sklearn.preprocessing import Imputer from sklearn.linear_model import LinearRegression from sklearn.tree import DecisionTreeRegressor import matplotlib.pyplot as plt from sklearn.preprocessing import Imputer from xgboost import XGBRegressortrain_path = r"C:\Users\cbattle\Desktop\train.csv" test_path = r"C:\Users\cbattle\Desktop\test.csv" out_path = r"C:\Users\cbattle\Desktop\out.csv"# 讀入數據 train = pd.read_csv(train_path) test = pd.read_csv(test_path) print('train:',train.shape) print('test :',test.shape)# 劃分X,y X = train.drop(['Id','SalePrice'],axis=1) y = train['SalePrice'] Xtest = test.drop(['Id'],axis=1) print('X :',X.shape) print('y :',y.shape) print('Xtest:',Xtest.shape) # for col in X: # print(X[col].dtype,col)key = [col for col in Xif X[col].dtype in ['int64','float64']or X[col].dtype == 'object' and X[col].nunique()<10] X = X[key] Xtest = Xtest[key]# 獨熱編碼 key = [col for col in Xif X[col].dtype in ['int64','float64']or X[col].dtype == 'object' and X[col].nunique()<10] X = X[key] Xtest = Xtest[key]print(X.shape, Xtest.shape) X = pd.get_dummies(X) Xtest = pd.get_dummies(Xtest) X, Xtest = X.align(Xtest, join = 'left', axis=1) print(X.shape, Xtest.shape)# 填補空值 my_imputer = Imputer() X = my_imputer.fit_transform(X) Xtest = my_imputer.transform(Xtest) print(X.shape, Xtest.shape)# 決策樹 # decisionTree = DecisionTreeRegressor() # decisionTree.fit(X,y) # ans = decisionTree.predict(Xtest)# XG boost xgb = XGBRegressor() xgb.fit(X,y,verbose=False) ans = xgb.predict(Xtest)# my_model = XGBRegressor(n_estimators=1000) # my_model.fit(train_X, train_y, early_stopping_rounds=5, # eval_set=[(val_X, val_y)], verbose=False) # ans = my_model.predict(Xtest)# 輸出 myAns = pd.DataFrame({'Id':test['Id'],'SalePrice':ans}) myAns.to_csv(r"C:\Users\cbattle\Desktop\out.csv", index=False) print('ok')

轉載于:https://www.cnblogs.com/cbattle/p/8810851.html

總結

以上是生活随笔為你收集整理的kaggle House_Price_XGBoost的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。