维度灾难

Python 中的降维

Jeroen Boeye

Head of Machine Learning, Faktion

从观测到模式

城市 价格
柏林 2
巴黎 3
Python 中的降维

从观测到模式

城市 价格
柏林 2
巴黎 3

简单分布图

Python 中的降维

从观测到模式

城市 价格
柏林 2.0
柏林 3.1
柏林 4.3
巴黎 3.0
巴黎 5.2
... ...

柏林 vs 巴黎分布

Python 中的降维

构建城市分类器——数据划分

将要预测的特征与用于训练的特征分开。

y = house_df['City']

X = house_df.drop('City', axis=1)

进行 70% 训练 / 30% 测试 划分

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
Python 中的降维

构建城市分类器——模型拟合

创建支持向量机分类器并拟合训练数据

from sklearn.svm import SVC

svc = SVC()

svc.fit(X_train, y_train)
Python 中的降维

构建城市分类器——预测

from sklearn.metrics import accuracy_score

print(accuracy_score(y_test, svc.predict(X_test)))
0.826
print(accuracy_score(y_train, svc.predict(X_train)))
0.832
Python 中的降维

添加特征

城市 价格
柏林 2.0
柏林 3.1
柏林 4.3
巴黎 3.0
巴黎 5.2
... ...

柏林 vs 巴黎分布

Python 中的降维

添加特征

城市 价格 n_floors n_bathroom surface_m2
柏林 2.0 1 1 190
柏林 3.1 2 1 187
柏林 4.3 2 2 240
巴黎 3.0 2 1 170
巴黎 5.2 2 2 290
... ... ... ... ...
Python 中的降维

让我们来练习!

Python 中的降维

Preparing Video For Download...