国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

這篇具有很好參考價值的文章主要介紹了【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

目錄

一、導入數(shù)據(jù)?

二、數(shù)據(jù)查看

可視化缺失值占比?

繪制所有變量的柱形圖,查看數(shù)據(jù)

查看各特征與目標變量price的相關性

三、數(shù)據(jù)處理

?處理異常值

查看seller,offerType的取值

查看特征 notRepairedDamage?

?異常值截斷

?填充缺失值?

?刪除取值無變化的特征

查看目標變量price

對price做對數(shù)log變換?

?四、特征構造

構造新特征:計算某品牌的銷售統(tǒng)計量?

??構造新特征:使用時間

對連續(xù)型特征數(shù)據(jù)進行分桶?

對數(shù)值型特征做歸一化?

?匿名特征交叉

平均數(shù)編碼?

五、特征篩選?

計算各列于交易價格的相關性?

對類別特征進行 OneEncoder?

切分特征和標簽?

用lightgbm篩選特征?


【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

?

一、導入數(shù)據(jù)?

import pandas as pd
import numpy as np
#coding:utf-8
#導入warnings包,利用過濾器來實現(xiàn)忽略警告語句。
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as plt
import seaborn as sns
import missingno as msno
#顯示所有列
pd.set_option('display.max_columns',None)
# #顯示所有行
# pd.set_option('display.max_rows',None)

Train_data = pd.read_csv("二手汽車價格預測/used_car_train_20200313.csv",sep=' ')
Test_data = pd.read_csv('二手汽車價格預測/used_car_testB_20200421.csv', sep=' ')
Train_data.shape,Test_data.shape#((150000, 31), (50000, 30))
Train_data.tail()
# Test_data.head()

二、數(shù)據(jù)查看

Train_data.info()
Data columns (total 31 columns):
 #   Column             Non-Null Count   Dtype  
---  ------             --------------   -----  
 0   SaleID             150000 non-null  int64  
 1   name               150000 non-null  int64  
 2   regDate            150000 non-null  int64  
 3   model              149999 non-null  float64
 4   brand              150000 non-null  int64  
 5   bodyType           145494 non-null  float64
 6   fuelType           141320 non-null  float64
 7   gearbox            144019 non-null  float64
 8   power              150000 non-null  int64  
 9   kilometer          150000 non-null  float64
 10  notRepairedDamage  150000 non-null  object 
 11  regionCode         150000 non-null  int64  
 12  seller             150000 non-null  int64  
 13  offerType          150000 non-null  int64  
 14  creatDate          150000 non-null  int64  
 15  price              150000 non-null  int64  
 16  v_0                150000 non-null  float64
 17  v_1                150000 non-null  float64
 18  v_2                150000 non-null  float64
 19  v_3                150000 non-null  float64
 20  v_4                150000 non-null  float64
 21  v_5                150000 non-null  float64
 22  v_6                150000 non-null  float64
 23  v_7                150000 non-null  float64
 24  v_8                150000 non-null  float64
 25  v_9                150000 non-null  float64
 26  v_10               150000 non-null  float64
 27  v_11               150000 non-null  float64
 28  v_12               150000 non-null  float64
 29  v_13               150000 non-null  float64
 30  v_14               150000 non-null  float64
dtypes: float64(20), int64(10), object(1)
Train_data.duplicated().sum()#沒有重復值
Train_data.isnull().sum()
SaleID                  0
name                    0
regDate                 0
model                   1
brand                   0
bodyType             4506
fuelType             8680
gearbox              5981
power                   0
kilometer               0
notRepairedDamage       0
regionCode              0
seller                  0
offerType               0
creatDate               0
price                   0
v_0                     0
v_1                     0
v_2                     0
v_3                     0
v_4                     0
v_5                     0
v_6                     0
v_7                     0
v_8                     0
v_9                     0
v_10                    0
v_11                    0
v_12                    0
v_13                    0
v_14                    0
dtype: int64

bodyType ,?fuelType,gearbox,model,這幾個特征存在缺失值。

可視化缺失值占比?

# nan可視化
missing = Train_data.isnull().sum()
missing = missing[missing > 0]
missing.sort_values(inplace=True)
missing.plot.bar()

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

繪制所有變量的柱形圖,查看數(shù)據(jù)


Train_data.hist(bins=50,figsize=(20,15))
plt.cla()  #清除axes

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

?圖中可以看出,seller,offerType,creatDate這幾個特征值分布不均勻,分別查看

查看各特征與目標變量price的相關性

#把字符串類型的變量、以及一些無關的變量去掉,獲得需要的列名
numeric_columns=Train_data.select_dtypes(exclude='object').columns
columns=[col for col in numeric_columns if col not in ['SaleID', 'name']]
#根據(jù)列名提取數(shù)據(jù)
train_set=Train_data[columns]
#計算各列于交易價格的相關性
correlation=train_set.corr()
correlation['price'].sort_values(ascending = False)
price         1.000000
v_12          0.692823
v_8           0.685798
v_0           0.628397
regDate       0.611959
gearbox       0.329075
bodyType      0.241303
power         0.219834
fuelType      0.200536
v_5           0.164317
model         0.136983
v_2           0.085322
v_6           0.068970
v_1           0.060914
v_14          0.035911
regionCode    0.014036
creatDate     0.002955
seller       -0.002004
v_13         -0.013993
brand        -0.043799
v_7          -0.053024
v_4          -0.147085
v_9          -0.206205
v_10         -0.246175
v_11         -0.275320
kilometer    -0.440519
v_3          -0.730946
offerType          NaN
Name: price, dtype: float64
f , ax = plt.subplots(figsize = (7, 7))

plt.title('Correlation of Numeric Features with Price',y=1,size=16)

sns.heatmap(correlation,square = True,  vmax=0.8)

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

三、數(shù)據(jù)處理

?處理異常值

  • 查看seller,offerType的取值

Train_data['seller'].value_counts()
#將seller其中的異常值1改為0
Train_data['seller'] = Train_data['seller'][Train_data['seller']==1]=0
Train_data['seller'].value_counts()

0    149999
1         1
Name: seller, dtype: int64
Train_data['offerType'].value_counts()
0    150000
Name: offerType, dtype: int64

可以看出,seller,offerType這兩個特征的取值無變化,幾乎倒向同一個值,可以刪除。

  • 查看特征 notRepairedDamage?

notRepairedDamage 中存在空缺值,但空缺值用“-”表示,所以數(shù)據(jù)查看發(fā)現(xiàn)不了空缺值,將“-”替換成NaN。

Train_data['notRepairedDamage'].value_counts()
Train_data['notRepairedDamage'].replace('-',np.nan,inplace = True)
0.0    111361
-       24324
1.0     14315
Name: notRepairedDamage, dtype: int64
Train_data['notRepairedDamage'].value_counts()
0.0    111361
1.0     14315
Name: notRepairedDamage, dtype: int64
  • ?異常值截斷

Train_data['power'].value_counts()
0       12829
75       9593
150      6495
60       6374
140      5963
        ...  
513         1
1993        1
19          1
751         1
549         1
Name: power, Length: 566, dtype: int64

?power在題目中要求范圍

power 發(fā)動機功率:范圍 [ 0, 600 ]

進行異常值截斷?

#異常值截斷
Train_data['power'][Train_data['power']>600]=600
Train_data['power'][Train_data['power']<1] = 1
Train_data['v_13'][Train_data['v_13']>6] = 6
Train_data['v_14'][Train_data['v_14']>4] = 4

?填充缺失值?

類別型特征用眾數(shù)填充缺失值?

?print(Train_data.bodyType.mode())
print(Train_data.fuelType.mode())
print(Train_data.gearbox.mode())
print(Train_data.model.mode())


?#用眾數(shù)填補空缺值
Train_data['bodyType']=Train_data['bodyType'].fillna(0)
Train_data['fuelType']=Train_data['fuelType'].fillna(0)
Train_data['gearbox']=Train_data['gearbox'].fillna(0)
Train_data['model']=Train_data['model'].fillna(0)

Train_data.isnull().sum()

?刪除取值無變化的特征

'seller','offerType'

#刪除取值沒有變化的列
Train_data.head()
Train_data = Train_data.drop(['seller','offerType'],axis = 1)
Train_data.head()

查看目標變量price


# 查看目標變量的skewness and kurtosis
sns.distplot(Train_data['price']);
print("Skewness: %f" % Train_data['price'].skew())#偏度
print("Kurtosis: %f" % Train_data['price'].kurt())#峰度

# Train_data.skew(), Train_data.kurt()
Skewness: 3.346487
Kurtosis: 18.995183

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

## 查看目標變量的具體頻數(shù)
## 繪制標簽的統(tǒng)計圖,查看標簽分布
plt.hist(Train_data['price'], orientation = 'vertical',histtype = 'bar', color ='red')
plt.show()

?【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

對price的長尾數(shù)據(jù)進行截取,做對數(shù)log變換?

np.log1p ( )?
數(shù)據(jù)預處理時首先可以對偏度比較大的數(shù)據(jù)用log1p函數(shù)進行轉(zhuǎn)化,使其更加服從高斯分布,此步處理可能會使我們后續(xù)的分類結果得到一個好的結果.


# 目標變量進行對數(shù)變換服從正態(tài)分布


Train_data['price'] = np.log1p(Train_data['price'])
plt.hist(Train_data['price'], orientation = 'vertical',histtype = 'bar', color ='red') 
plt.show()

sns.distplot(Train_data['price']);
print("Skewness: %f" % Train_data['price'].skew())#偏度
print("Kurtosis: %f" % Train_data['price'].kurt())#峰度

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

Skewness: -0.261727
Kurtosis: -0.182127

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

?四、特征構造

4.1、構造新特征:計算某品牌的銷售統(tǒng)計量?

# 計算某品牌的銷售統(tǒng)計量
Train_gb = Train_data.groupby("brand")
all_info = {}
for kind, kind_data in Train_gb:
    info = {}
    kind_data = kind_data[kind_data['price'] > 0]
    info['brand_amount'] = len(kind_data)
    info['brand_price_max'] = kind_data.price.max()
    info['brand_price_median'] = kind_data.price.median()
    info['brand_price_min'] = kind_data.price.min()
    info['brand_price_sum'] = kind_data.price.sum()
    info['brand_price_std'] = kind_data.price.std()
    info['brand_price_average'] = round(kind_data.price.sum() / (len(kind_data) + 1), 2)
    all_info[kind] = info
brand_fe = pd.DataFrame(all_info).T.reset_index().rename(columns={"index": "brand"})
Train_data = Train_data.merge(brand_fe, how='left', on='brand')

?4.2、構造新特征:使用時間

一般來說汽車價格與使用時間成反比

# 使用時間:
Train_data['creatDate'] - Train_data['regDate']#一般來說汽車價格與使用時間成反比
# 數(shù)據(jù)里有時間出錯的格式,errors='coerce',遇到不能轉(zhuǎn)換的數(shù)據(jù)賦值為nan
Train_data['used_time'] = (pd.to_datetime(Train_data['creatDate'], format='%Y%m%d', errors='coerce') - 
                            pd.to_datetime(Train_data['regDate'], format='%Y%m%d', errors='coerce')).dt.days

Train_data['used_time'].isnull().sum()
Train_data['used_time'].mean()#4432.082407160321

#用平均數(shù)或眾數(shù)填充缺失值
Train_data['used_time'].fillna(4432,inplace = True)
Train_data['used_time'].isnull().sum()

4.3、對連續(xù)型特征數(shù)據(jù)進行分桶?

#對連續(xù)型數(shù)據(jù)進行分桶
#對power進行分桶
bin = [i*10 for i in range(31)]#分成30個桶
Train_data['power_bin'] = pd.cut(Train_data['power'], bin, labels=False)
Train_data[['power_bin', 'power']].head()

?kilometer已經(jīng)分桶了

plt.hist(Train_data['kilometer'])
# 刪除不需要的數(shù)據(jù)
Train_data = Train_data.drop(['name','SaleID', 'regionCode'], axis=1)
Train_data.head()
  • 目前的數(shù)據(jù)其實已經(jīng)可以給樹模型使用了,所以我們導出一下

Train_data.to_csv('data_for_tree.csv', index=0)

4.5、對數(shù)值型特征做歸一化?

# 我們可以再構造一份特征給 LR NN 之類的模型用
# 之所以分開構造是因為,不同模型對數(shù)據(jù)集的要求不同
# 我們看下數(shù)據(jù)分布:

Train_data['power'].plot.hist()

?【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

# 我們對其取 log,在做歸一化
from sklearn import preprocessing
min_max_scaler = preprocessing.MinMaxScaler()
Train_data['power'] = np.log1p(Train_data['power'] + 1) 
Train_data['power'] = Train_data['power'] = max_min(Train_data['power'])
Train_data['power'].plot.hist()

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

# kilometer做過分桶處理了,所以我們可以直接做歸一化
Train_data['kilometer'] =  max_min(Train_data['kilometer'])
Train_data['kilometer'].plot.hist()

【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測

# 對之前構造的以下特征進行歸一化
# 'brand_amount', 'brand_price_average', 'brand_price_max',
# 'brand_price_median', 'brand_price_min', 'brand_price_std',
# 'brand_price_sum'
# 這里不再一一舉例分析了,直接做變換,
def max_min(x):
    return (x - np.min(x)) / (np.max(x) - np.min(x))

# Train_data['brand_amount'] = max_min(Train_data['brand_amount'])
Train_data['brand_price_average'] =  max_min(Train_data['brand_price_average'] )
Train_data['brand_price_max'] =  max_min(Train_data['brand_price_max'])
Train_data['brand_price_median'] =  max_min(Train_data['brand_price_max'])
Train_data['brand_price_min'] =  max_min(Train_data['brand_price_min'])
Train_data['brand_price_std'] =  max_min(Train_data['brand_price_std'])
Train_data['brand_price_sum'] =  max_min(Train_data['brand_price_sum'] )
Train_data.head()

?4.6、匿名特征交叉

#匿名特征交叉
num_cols = [0,2,3,6,8,10,12,14]
for index, value in enumerate(num_cols):
    for j in num_cols[index+1:]:
        Train_data['new'+str(value)+'*'+str(j)]=Train_data['v_'+str(value)]*Train_data['v_'+str(j)]
        Train_data['new'+str(value)+'+'+str(j)]=Train_data['v_'+str(value)]+Train_data['v_'+str(j)]
        Train_data['new'+str(value)+'-'+str(j)]=Train_data['v_'+str(value)]-Train_data['v_'+str(j)]
num_cols1 = [3,5,1,11]

for index, value in enumerate(num_cols1):
    for j in num_cols1[index+1:]:
        Train_data['new'+str(value)+'-'+str(j)]=Train_data['v_'+str(value)]-Train_data['v_'+str(j)]
 

for i in range(15):
    Train_data['new'+str(i)+'*year']=Train_data['v_'+str(i)] * Train_data['used_time']
    
# 這份數(shù)據(jù)可以給 LR 用
Train_data.to_csv('Train_data_for_lr.csv', index=0)
Train_data.head()

五、特征篩選?

5.1、查看各列于交易價格的相關性


correlation=Train_data.corr()
x=correlation['price'].sort_values(ascending = False)
y = np.abs(x)>=0.01

5.2、對類別特征進行 OneEncoder?

data = pd.get_dummies(data, columns=['model', 'brand', 'bodyType', 'fuelType',
                                     'gearbox', 'notRepairedDamage', 'power_bin'])
print(data.shape)
data.columns
(200000, 364)
Index(['SaleID', 'name', 'regDate', 'power', 'kilometer', 'regionCode',
       'creatDate', 'price', 'v_0', 'v_1',
       ...
       'power_bin_20.0', 'power_bin_21.0', 'power_bin_22.0', 'power_bin_23.0',
       'power_bin_24.0', 'power_bin_25.0', 'power_bin_26.0', 'power_bin_27.0',
       'power_bin_28.0', 'power_bin_29.0'],
      dtype='object', length=364)

5.3、切分特征和標簽?

#切分特征和標簽
train_set=Train_data.copy()
y_train=train_set['price']

x_train=train_set.drop(['price','regDate','creatDate'],axis = 1
                      )
x_train.head()

用lightgbm篩選特征?

import lightgbm as lgb
from sklearn.model_selection import train_test_split 
im
from sklearn.metrics import mean_squared_error as MSE


features = pd.get_dummies(x_train)
feature_names = list(features.columns)
features = np.array(features)
labels = np.array(y_train).reshape((-1, ))
feature_importance_values = np.zeros(len(feature_names))
task='regression'
early_stopping=True
eval_metric= 'l2'
n_iterations=10

for _ in range(n_iterations):
    if task == 'classification':
        model = lgb.LGBMClassifier(n_estimators=1000, learning_rate = 0.05, verbose = -1)
    if task =='regression':
        model = lgb.LGBMRegressor(n_estimators=1000, learning_rate = 0.05, verbose = -1)
    else:
        raise ValueError('Task must be either "classification" or "regression"')
    #提前終止訓練,需要驗證集
    if early_stopping:
        train_features, valid_features, train_labels, valid_labels = train_test_split(features, labels, test_size = 0.15)
  # Train the model with early stopping
        model.fit(train_features, train_labels, eval_metric = eval_metric,eval_set = [(valid_features, valid_labels)],early_stopping_rounds = 100, verbose = -1)
        gc.enable()
        del train_features, train_labels, valid_features, valid_labels
        gc.collect()
  
    else:
        model.fit(features, labels)
  # Record the feature importances
    feature_importance_values += model.feature_importances_ / n_iterations
    feature_importances = pd.DataFrame({'feature': feature_names, 'importance': feature_importance_values})
        
#按照重要性大小對特征進行排序
feature_importances = feature_importances.sort_values('importance', ascending = False).reset_index(drop = True)

#計算特征的相對重要性,全部特征的相對重要性之和為1
feature_importances['normalized_importance'] = feature_importances['importance'] / feature_importances['importance'].sum()

#計算特征的累計重要性
#cutsum :返回給定 axis 上的累計和
feature_importances['cumulative_importance'] = np.cumsum(feature_importances['normalized_importance'])

#選取累計重要性大于0.99的特征,這些特征將會被刪除掉。
drop_columns=list(feature_importances.query('cumulative_importance>0.99')['feature'])
#去掉重要度低的列
x_set=x_train.copy()
x_set.drop(drop_columns,axis=1,inplace=True)

#對數(shù)據(jù)集總體概覽
#顯示所有行
pd.set_option("display.max_info_columns", 300)   # 設置info中信息顯示數(shù)量為200
x_set.info()

六、建模調(diào)參

# 構建模型擬合的評價指標
from sklearn.metrics import mean_squared_error,mean_absolute_error

def model_goodness(model,x,y):
    prediction=model.predict(x)
    mae=mean_absolute_error(y,prediction)
    mse=mean_squared_error(y,prediction)
    rmse=np.sqrt(mse)

    print('MAE:',mae)#絕對平均誤差
    print('MSE:',mse)#均方差
    print('RMSE:',rmse)#均方根
# 定義模型泛化能力的指標計算函數(shù):
from sklearn.model_selection import cross_val_score
def display_scores(scores):
        print("Scores:", scores)    
        print("Mean:", scores.mean())
        print("Standard deviation:", scores.std())
#先用簡單線性回歸模型擬合
from sklearn.linear_model import LinearRegression
lin_reg=LinearRegression()
lin_reg.fit(x_set,y_train)

model_goodness(lin_reg,x_set,y_train)
'''MAE: 0.17541397968387218
MSE: 0.07846792179703589
RMSE: 0.28012126266500353'''

隨機森林?

from sklearn.ensemble import RandomForestRegressor
forest_reg=RandomForestRegressor()0

forest_reg.fit(x_set,y_train)

model_goodness(forest_reg,x_set,y_train)


# 采用10折交叉驗證的方法來驗證模型的泛化能力
scores=cross_val_score(forest_reg,x_set,y_train,scoring='neg_mean_absolute_error',cv=10)
mae_scores=np.abs(-scores)
display_scores(mae_scores)

''MAE: 0.047468466346616035
MSE: 0.008013848284210116
RMSE: 0.08952009988941095'''

存在過擬合,

'''Scores: [0.1294032 ?0.12707153 0.12940989 0.12829302 0.13042102 0.1285104
?0.12762524 0.12703461 0.1289176 ?0.12968754]
Mean: 0.12863740448866307
Standard deviation: 0.0010828607409916612'''

?GBDT?

# GBDT
from sklearn.ensemble import GradientBoostingRegressor
gbrt=GradientBoostingRegressor()
gbrt.fit(x_set,y_train)

model_goodness(gbrt,x_set,y_train)


scores=cross_val_score(gbrt,x_set,y_train,scoring='neg_mean_absolute_error',cv=10)
mae_scores=np.abs(scores)
display_scores(mae_scores)


MAE: 0.1579591089700307
MSE: 0.06534997589709124
RMSE: 0.2556364134803398


Scores: [0.16032467 0.15964983 0.16159922 0.15899314 0.16286916 0.16034439
?0.15793287 0.1580428 ?0.15949101 0.16185252]
Mean: 0.16010996168246888
Standard deviation: 0.0015434916175588425

XGBoost

# XGBoost
import lightgbm as lgb
import xgboost as xgb
xgb_reg= xgb.XGBRegressor()
xgb_reg.fit(x_set,y_train)

model_goodness(xgb_reg,x_set,y_train)
scores=cross_val_score(xgb_reg,x_set,y_train,scoring='neg_mean_absolute_error',cv=10)
mae_scores=np.abs(scores)
display_scores(mae_scores)

'''
MAE: 0.11684430449593118
MSE: 0.03652492452344296
RMSE: 0.1911149510724971
Scores: [0.13500033 0.1333282 ?0.13477914 0.13414655 0.1365417 ?0.13534464
?0.13483075 0.13339024 0.1352027 ?0.13584453]
Mean: 0.1348408781266727
Standard deviation: 0.000958580534103817'''?

LightGBM?

#LightGBM
lgb_reg=lgb.LGBMRegressor()
lgb_reg.fit(x_set,y_train)


model_goodness(lgb_reg,x_set,y_train)

scores=cross_val_score(lgb_reg,x_set,y_train,scoring='neg_mean_absolute_error',cv=10)
mae_scores=np.abs(scores)
display_scores(mae_scores)

'''
MAE: 0.1307250662409778
MSE: 0.049472769306324126
RMSE: 0.22242474976118132
Scores: [0.13610695 0.13486826 0.13710767 0.13597915 0.13788547 0.13687976
?0.13471174 0.13481778 0.13525209 0.13684043]
Mean: 0.13604493148788416
Standard deviation: 0.0010560012820324028'''

還缺個模型調(diào)參和模型融合,回頭補

調(diào)參

1.利用隨機搜索對隨機森林模型進行調(diào)優(yōu)

利用sklearn.model_selection模塊中的RandomizedSearchCV來進行隨機搜索,搜索的超參數(shù)包括bootstrap,最大特征數(shù)max_features,樹的最大深度max_depth,n_estimators。

from sklearn.model_selection import RandomizedSearchCV

#2.設置參數(shù)空間
from hyperopt import hp
space_forest = {
    'bootstrap':[True,False],
    'max_features':list(range(0,25,1)),
    'max_depth': list(range(0, 100, 1)),
    'n_estimators': list(range(30, 150, 1))
}
#隨機搜索,利用5折交叉驗證得分來作為模型優(yōu)劣的判斷標準
forest_reg=RandomForestRegressor()
random_search=RandomizedSearchCV(forest_reg, space_forest,cv=5,scoring='neg_mean_squared_error')

#得到最優(yōu)參數(shù)
random_search.best_params_

2.利用貝葉斯方法對LightBoost進行調(diào)優(yōu)
python中的hypreopt包可以進行貝葉斯方法的調(diào)優(yōu),這篇文章里Python 環(huán)境下的自動化機器學習超參數(shù)調(diào)優(yōu),有詳細的介紹。?

# 貝葉斯方法對LightBoost進行調(diào)優(yōu)

#2.定義參數(shù)空間
from hyperopt import hp
space = {
    'num_leaves': hp.quniform('num_leaves', 30, 150, 1),
    'learning_rate': hp.loguniform('learning_rate', np.log(0.01), np.log(0.2)),
    'subsample_for_bin': hp.quniform('subsample_for_bin', 20000, 300000, 20000),
    'max_depth': hp.quniform('max_depth', 0, 100, 1),
    'n_estimators': hp.quniform('n_estimators', 30, 150, 1)
}

#定義優(yōu)化函數(shù),即為5折交叉驗證的得分
from sklearn.model_selection import cross_val_score
def objective(params, n_folds=5):
    num_leaf=int(params['num_leaves'])
    estimator=int(params['n_estimators'])
    rate=params['learning_rate']
    sub_for_bin=int(params['subsample_for_bin'])
    max_dep=int(params['max_depth'])
    lgb_reg=lgb.LGBMRegressor(num_leaves=num_leaf,n_estimators = estimator,learning_rate=rate,subsample_for_bin=sub_for_bin,max_depth=max_dep)
    lgb_reg.fit(x_set,y_train)
    scores=cross_val_score(lgb_reg,x_set,y_train,scoring='neg_mean_absolute_error',cv=5)
    mae_scores=np.abs(scores)
    loss=mae_scores.mean()
    return loss

#尋找到使優(yōu)化函數(shù)最小超參數(shù)組合,利用hyperopt中的fmin來求最小化
from hyperopt import Trials,fmin,tpe
best = fmin(fn = objective, space = space, algo = tpe.suggest, max_evals = 500)

?待補充。。。

天池長期賽:二手車價格預測(422方案分享)

阿里天池競賽項目——二手車交易價格預測

基于Python實現(xiàn)的二手車價格預測_biyezuopin的博客-CSDN博客_python二手車價格預測

?平均數(shù)編碼:針對高基數(shù)定性特征(類別特征)的數(shù)據(jù)預處理/特征工程 - 知乎 (zhihu.com)文章來源地址http://www.zghlxwxcb.cn/news/detail-426380.html

到了這里,關于【數(shù)據(jù)挖掘競賽】零基礎入門數(shù)據(jù)挖掘-二手汽車價格預測的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 【天池課堂】零基礎入門數(shù)據(jù)挖掘-課程匯總

    寫在前面: 如果你現(xiàn)在很迷茫,但是又對數(shù)據(jù)挖掘感興趣,建議先看看以下兩個視頻直播,兩位大佬親身講述自己和數(shù)據(jù)挖掘的前世今生。 《如何入門數(shù)據(jù)挖掘競賽》 魚遇雨欲語與余。天池明星選手,武漢大學碩士,天池數(shù)據(jù)科學家,數(shù)據(jù)競賽愛好者。 《數(shù)據(jù)挖掘競賽指南

    2024年03月13日
    瀏覽(22)
  • 一零六五、零基礎入門數(shù)據(jù)挖掘-心跳信號分類預測(阿里云天池賽)

    一零六五、零基礎入門數(shù)據(jù)挖掘-心跳信號分類預測(阿里云天池賽)

    目錄 賽制官方鏈接 賽題簡介 賽制說明 長期賽(2021年7月~) 正式賽(3月12日 - 5月12日) 大賽組織 賽題背景 賽題數(shù)據(jù) 評測標準 結果提交 ?代碼實現(xiàn) ? 賽制官方鏈接 零基礎入門數(shù)據(jù)挖掘-心跳信號分類預測_學習賽_天池大賽-阿里云天池 賽題簡介 本次新人賽是Datawhale與天池

    2024年02月16日
    瀏覽(19)
  • 【數(shù)據(jù)挖掘競賽】——科大訊飛:鋰離子電池生產(chǎn)參數(shù)調(diào)控及生產(chǎn)溫度預測挑戰(zhàn)賽

    【數(shù)據(jù)挖掘競賽】——科大訊飛:鋰離子電池生產(chǎn)參數(shù)調(diào)控及生產(chǎn)溫度預測挑戰(zhàn)賽

    ???♂? 個人主頁:@Lingxw_w的個人主頁 ???作者簡介:計算機科學與技術研究生在讀 ?? 希望大家多多支持,我們一起進步!?? 如果文章對你有幫助的話, 歡迎評論 ??點贊???? 收藏 ??加關注+? 【科大訊飛】報名鏈接:https://challenge.xfyun.cn?invitaCode=GQTcFX? 目錄 一、賽

    2024年02月14日
    瀏覽(29)
  • 數(shù)據(jù)分析技能點-數(shù)據(jù)挖掘及入門

    在數(shù)字化的世界里,數(shù)據(jù)像是一種新的貨幣。它不僅推動了科技創(chuàng)新,還在塑造著我們的生活、工作和思維方式。但數(shù)據(jù)本身并不是目的,真正的價值在于如何從海量的數(shù)據(jù)中提煉有用的信息和知識。這正是數(shù)據(jù)挖掘發(fā)揮作用的地方。 數(shù)據(jù)挖掘是從大量的、不完整的、噪聲的

    2024年02月07日
    瀏覽(24)
  • 數(shù)據(jù)采集:數(shù)據(jù)挖掘的基礎

    數(shù)據(jù)采集:數(shù)據(jù)挖掘的基礎

    ??????????歡迎來到我的博客?????????? ??作者: 秋無之地 ??簡介:CSDN爬蟲、后端、大數(shù)據(jù)領域創(chuàng)作者。目前從事python爬蟲、后端和大數(shù)據(jù)等相關工作,主要擅長領域有:爬蟲、后端、大數(shù)據(jù)開發(fā)、數(shù)據(jù)分析等。 ??歡迎小伙伴們 點贊????、收藏

    2024年02月08日
    瀏覽(20)
  • 【數(shù)據(jù)挖掘】練習1:R入門

    【數(shù)據(jù)挖掘】練習1:R入門

    課后作業(yè)1:R入門 一:習題內(nèi)容 1.要與R交互必須安裝Rstudio,這種說法對不對? 不對。雖然RStudio是一個流行的R交互集成開發(fā)環(huán)境,但并不是與R交互的唯一方式。 與R交互可以采用以下幾種方法: 使用R Console :R語言自帶了一個控制臺界面。這種方式不需要安裝任何額外的軟

    2024年03月13日
    瀏覽(26)
  • 《數(shù)據(jù)挖掘基礎》實驗:Weka平臺實現(xiàn)關聯(lián)規(guī)則挖掘

    《數(shù)據(jù)挖掘基礎》實驗:Weka平臺實現(xiàn)關聯(lián)規(guī)則挖掘

    進一步理解關聯(lián)規(guī)則算法(Apriori算法、FP-tree算法),利用weka實現(xiàn)數(shù)據(jù)集的挖掘處理,學會調(diào)整模型參數(shù),讀懂挖掘規(guī)則,解釋規(guī)則的含義 (1)隨機選取數(shù)據(jù)集為對象,完成以下內(nèi)容:(用兩種方法:Apriori算法、FP-tree算法) 文件導入與編輯; 參數(shù)設置說明; 結果截圖;

    2024年02月02日
    瀏覽(98)
  • 【數(shù)據(jù)挖掘從入門到實戰(zhàn)】——專欄導讀

    【數(shù)據(jù)挖掘從入門到實戰(zhàn)】——專欄導讀

    目錄 1、專欄大綱 ??基礎部分 ??實戰(zhàn)部分 ??競賽部分 2、代碼附錄 數(shù)據(jù)挖掘?qū)?,包含基本?數(shù)據(jù)挖掘算法分析和實戰(zhàn),數(shù)據(jù)挖掘競賽干貨分享 等。數(shù)據(jù)挖掘是從大規(guī)模數(shù)據(jù)集中發(fā)現(xiàn)隱藏模式、關聯(lián)和知識的過程。它結合了統(tǒng)計學、人工智能和數(shù)據(jù)庫系統(tǒng)等領域的技術和

    2024年02月13日
    瀏覽(23)
  • 【Python爬蟲實戰(zhàn)】汽車城最好的十款車,第一名竟是這款車...Python教你一鍵采集二手車數(shù)據(jù)信息實現(xiàn)數(shù)據(jù)可視化展示哦~(附視頻教程)

    【Python爬蟲實戰(zhàn)】汽車城最好的十款車,第一名竟是這款車...Python教你一鍵采集二手車數(shù)據(jù)信息實現(xiàn)數(shù)據(jù)可視化展示哦~(附視頻教程)

    駕考不易,天天早起去練車,無論烈日還是下雨,通通都在室外進行,但想要拿證,一定要堅 持不懈的去練車。 粉絲白嫖源碼福利,請移步至CSDN社區(qū)或文末公眾hao即可免費。 小編就是在一復一日的練習中,終于得到了我人生中以為不可能考證之駕照到手了! 這不?駕照到

    2024年02月02日
    瀏覽(29)
  • Python數(shù)據(jù)挖掘:入門、進階與實用案例分析——基于非侵入式負荷檢測與分解的電力數(shù)據(jù)挖掘

    Python數(shù)據(jù)挖掘:入門、進階與實用案例分析——基于非侵入式負荷檢測與分解的電力數(shù)據(jù)挖掘

    本案例將根據(jù)已收集到的電力數(shù)據(jù),深度挖掘各電力設備的電流、電壓和功率等情況,分析各電力設備的實際用電量,進而為電力公司制定電能能源策略提供一定的參考依據(jù)。更多詳細內(nèi)容請參考《Python數(shù)據(jù)挖掘:入門進階與實用案例分析》一書。 為了更好地監(jiān)測用電設備的

    2024年02月08日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包