<jupyter_start><jupyter_text>imports<jupyter_code>import xgboost as xg
import numpy as np
import pandas as pd
import seaborn as sns
data=pd.read_table('data-46-raw.txt', error_bad_lines=False)<jupyter_output><empty_output><jupyter_text>Showing Data<jupyter_code>data
store=pd.read_excel('store.xlsx',sheet_name='门店')
store<jupyter_output><empty_output><jupyter_text>计算坪效<jupyter_code>store['revenue_per_sqm']=store['出账收入']/store['门店面积(㎡)']
store.columns
revenue_per_sqm=store['revenue_per_sqm']
revenue_per_sqm<jupyter_output><empty_output><jupyter_text>导入xgboost<jupyter_code>from sklearn.model_selection import train_test_split
from xgboost.sklearn import XGBClassifier

X_train, X_test, y_train, y_test = train_test_split(data, revenue_per_sqm, test_size=0.1, random_state=0)
from sklearn import metrics
def xgbtrain(X_train, X_test, y_train, y_test):
    model=xg.XGBRegressor(max_depth=5, learning_rate=0.1, n_estimators=100, silent=True, objective='reg:gamma')
    model.fit(X_train,y_train)
    ans=model.predict(X_test)
    ans1=model.predict(X_train)
    r2_score=metrics.r2_score(y_test,ans)
    r2_score1=metrics.r2_score(y_train,ans1)
    print("The training performance(r2_score) on test set is",r2_score)
    print("The training performance(r2_score) on training set is",r2_score1)
def split(X,y,testsize,seed):
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=testsize, random_state=seed)
    return X_train, X_test, y_train, y_test<jupyter_output><empty_output><jupyter_text>数据处理：标准化<jupyter_code>from sklearn.preprocessing import StandardScaler
SS=StandardScaler()
Sdata=SS.fit_transform(data.fillna(0))
revenue=pd.DataFrame(revenue_per_sqm)
Srevenue_psqm=SS.fit_transform(revenue)
Srevenue_psqm=Srevenue_psqm+1
X_train, X_test, y_train, y_test=split(Sdata,revenue_per_sqm,0.1,0)
X_train<jupyter_output><empty_output><jupyter_text>数据简单标准化后跑了一遍，效果很差<jupyter_code>xgbtrain(X_train, X_test, y_train, y_test)<jupyter_output>The training performance(r2_score) on test set is -0.15051228222724733
The training performance(r2_score) on training set is 0.5452474787967462<jupyter_text>试了一下pca，看了一下最主要的元素，感觉基本没救了<jupyter_code>from sklearn.decomposition import PCA
pca=PCA(n_components=0.7)
Pdata=pca.fit_transform(Sdata)
print (pca.explained_variance_ratio_)
print (pca.explained_variance_)
print (pca.n_components_)
Pdata
X_train, X_test, y_train, y_test=split(Pdata,revenue_per_sqm,0.1,5)
xgbtrain(X_train, X_test, y_train, y_test)
import matplotlib.pyplot as plt
plt.scatter(Pdata,revenue_per_sqm)
r=pd.DataFrame(revenue_per_sqm)
p=pd.DataFrame(Pdata)
frames=[p,r]
datanew=pd.concat(frames,axis=1,ignore_index=True)
datanew
datanew.columns=['x','y']
datanew=datanew[datanew['x']<30]

datanew=datanew[datanew['y']<8000]
plt.scatter(datanew.x,datanew.y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11758436944937833, 'fraction_numerical': 0.027353463587921848, 'mean_word_length': 10.782426778242678, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '348408', 'license': 'MIT', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1241, 'n_words': 152, 'path': 'suxia_xgboost_first_trial.ipynb', 'repo_name': 'Mercury0919/MLinSiteSelection', 'size': '2815'}