如何评估DecisionTreeGressor python的输出

如何评估DecisionTreeGressor python的输出,python,scikit-learn,evaluation,Python,Scikit Learn,Evaluation,我试图使用sklearn python的DecisionTreeGressor来找出两个变量X轴预紧和y轴接收光功率之间的依赖关系。我正在测量两个参数,如*/1min 当我在matlab中使用polyval和polyfit时,我能够提取 实际预测方程或多或少地描述了两者之间的关系 接收光功率=f(预压) 我认为我的问题基本上是在使用DecisionTreeGressor时如何评估我的分析结果。我指的是实际方程、残差以及如何计算提取曲线的实际误差 我在localhost上使用jupyter笔记本p

我试图使用sklearn python的DecisionTreeGressor来找出两个变量X轴预紧和y轴接收光功率之间的依赖关系。我正在测量两个参数,如*/1min

当我在matlab中使用polyval和polyfit时,我能够提取 实际预测方程或多或少地描述了两者之间的关系

接收光功率=f(预压)

我认为我的问题基本上是在使用DecisionTreeGressor时如何评估我的分析结果。我指的是实际方程、残差以及如何计算提取曲线的实际误差

我在localhost上使用jupyter笔记本python进行项目,只是因为我的输入final.merged.txt文件大约有10 MB

预压第3列!!!!

我非常感谢你的建议

print(__doc__)

# Import the necessary modules and libraries
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeRegressor
import matplotlib.pyplot as plt

# Create a random dataset
rng = np.random.RandomState(1)
# X = np.sort(5 * rng.rand(80, 1), axis=0)
# y = np.sin(X).ravel()
# y[::5] += 3 * (0.5 - rng.rand(16))


X = pd.read_csv('final.merged.txt',sep = ";",usecols=[3])  # -- toto funguje !!
#X = pd.read_csv('final.merged.txt',sep = ";",usecols=(3,5,6,7,9,10))
#X = X.loc[:,'avgPressure'].values
y = pd.read_csv('final.merged.txt',sep = ";",usecols=[1])
# y = y.ix[:,0]
y = y.loc[:,'received optical power'].values

# Fit regression model
regr_1 = DecisionTreeRegressor(max_depth=2)
regr_2 = DecisionTreeRegressor(max_depth=5)
regr_3 = DecisionTreeRegressor(max_depth=10)

regr_1.fit(X, y)
regr_2.fit(X, y)
regr_3.fit(X, y)


# Predict
#X_test = np.arange(0.0, 5.0, 0.01)[:, np.newaxis]
#X_test =xrange(X.min(),X.max())
X_test = np.arange(X.min(), X.max(), (X.max()-X.min())/len(X))

print "vector y: %s\nvector X: %s\nX_test: %s" % (len(y), len(X),len(X_test))
len(X_test) is len(y)
X_test=pd.DataFrame(X_test,columns = ['X_test'])

y_1 = regr_1.predict(X_test)
y_2 = regr_2.predict(X_test)
y_3 = regr_3.predict(X_test)



# Plot the results
plt.figure()
plt.scatter(X, y, c="darkorange", label="data")
plt.plot(X_test, y_1, color="cornflowerblue", label="max_depth=2", linewidth=2)
plt.plot(X_test, y_2, color="yellowgreen", label="max_depth=5", linewidth=2)
plt.plot(X_test, y_3, color="red", label="max_depth=10", linewidth=2)

plt.xlabel("data")
plt.ylabel("target")
plt.title("Decision Tree Regression")
plt.legend()
plt.show()