2020-01-02

  1. 修改配置文件$HADOOP_HOME/etc/hadoop/mapred-site.xml
     data.loc[index, 'video_memory_value'] = re.sub('\D', '', data.loc[index, 'video_memory'])
     if data.loc[index, 'video_memory_value'] == '':
         data.loc[index, 'video_memory_value'] = float(0)
     else:
         data.loc[index, 'video_memory_value'] = float(data.loc[index, 'video_memory_value'])
    
    cpu_mapping = {'i3':3, 'i5':5, 'i7':7, 'i9':9, 'AMD':6}
    data['cpu'] = data['cpu'].map(cpu_mapping)
    
    data = data.join(pd.get_dummies(data[['brand', 'video_card']]))
    
    data = data.drop_duplicates()
    data = data.dropna(axis=0, how='any')
    
     screen_pixels = re.findall(r'\d+', data.loc[index, 'screen_pixels'])
     if len(screen_pixels) >= 2:
         data.loc[index, 'screen_pixels_x'] = float(screen_pixels[0])
         data.loc[index, 'screen_pixels_y'] = float(screen_pixels[1])
    
     ssd_value = re.findall('\d+', str(data.loc[index, 'ssd']))
     if len(ssd_value) > 0:
         data.loc[index, 'ssd_value'] = float(ssd_value[0])
     else:
         data.loc[index, 'ssd_value'] = 0
    
     def ridge_model(train_data, test_data, train_target, test_target):
         param_alpha = {'alpha':[1.0, 0.1, 0.01, 0.001]}
         estimator = Ridge()
         estimator = GridSearchCV(estimator, param_grid=param_alpha)
         estimator.fit(train_data, train_target)
         print('RIDGE最佳参数alpha:', estimator.best_params_)
         print('RIDGE最佳得分:', estimator.best_score_)
         estimator = estimator.best_estimator_
         print('RIDGE损失函数值MAE:%.2f' % 
         np.divide(np.sum(np.absolute(estimator.predict(test_data) - test_target)), len(test_target)))
         print('RIDGE预测性能得分:%.2f' % estimator.score(test_data, test_target))
    
    
     RIDGE最佳参数alpha: {'alpha': 0.1}
     RIDGE最佳得分: 0.36026660370026786
     RIDGE损失函数值MAE:27.46
     RIDGE预测性能得分:0.54
    
    
     data_columns = data.columns
     min_max_scaler = MinMaxScaler()
     data = min_max_scaler.fit_transform(data)
     data = pd.DataFrame(data)
     data.columns = data_columns
    
    
     def xgb_model(train_data, test_data, train_target, test_target):
         param_learning_rate = {'learning_rate':[1.0, 0.1, 0.01, 0.001], 'max_depth':[3, 4, 5, 6, 7, 8], 'n_estimators':[10, 20, 30, 50, 70, 90, 100, 120, 140, 160, 200, 230, 260, 300]}
         estimator = xgb.XGBRegressor(silent=False, objective='reg:gamma')
         estimator = GridSearchCV(estimator, param_grid=param_learning_rate)
         estimator.fit(train_data, train_target)
         print('XGB最佳参数learning_rate:', estimator.best_params_)
         print('XGB最佳得分:', estimator.best_score_)
    
         estimator = estimator.best_estimator_
         predict_target = estimator.predict(test_data)
    
         actual_target = []
         for index, row in test_target.iterrows():
             comment_count = row['comment_count']
             actual_target.append(comment_count)
    
         mae_value = np.divide(np.sum(np.absolute(predict_target - actual_target)), len(actual_target))
         print('XGB损失函数值MAE:%.2f' % mae_value )
         print('XGB预测性能得分:%.2f' % estimator.score(test_data, test_target))
    
    
    

你可能感兴趣的:(2020-01-02)