使用受限制的boltzmann计算机填充pandas数据帧中缺少的值。
sherlockml-boltzmannclean的Python项目详细描述
使用受限的boltzmann机器填充pandas数据帧中缺少的值。
提供一个实现scikit learn transformer接口的类,用于创建和训练受限的boltzmann机器。然后可以从中进行采样,以填充训练数据或相同格式的新数据中缺少的值。提供了将转换应用于pandas数据帧的实用程序函数,可以将列视为连续的数字或分类特征。
安装
pip install sherlockml-boltzmannclean
用法
为了用最少的忙乱填充数据帧中丢失的值,提供了一个清理功能。
importboltzmanncleanmy_clean_dataframe=boltzmannclean.clean(dataframe=my_dataframe,numerical_columns=['Height','Weight'],categorical_columns=['Colour','Shape'],tune_rbm=True# tune RBM hyperparameters for my data)
创建和使用底层scikit learn transformer。
my_rbm=boltzmannclean.RestrictedBoltzmannMachine(n_hidden=100,learn_rate=0.01,batchsize=10,dropout_fraction=0.5,max_epochs=1,adagrad=True)my_rbm.fit_transform(a_numpy_array)
这里,默认的rbm超参数是上面列出的那些参数,在上面操作的numpy数组应该完全由[0,1]或np.nan/none范围内的数字组成。超参数是:
- n_hidden:隐藏层的大小
- 学习率:随机梯度下降的学习率
- batchSize:随机梯度下降的batchSize
- dropout_fraction:训练过程中每次向后传球时要退出的隐藏节点的分数
- {EM1}$Max LeimChels
:训练数据上的最大传递数< /LI> - adagrad:是否对随机梯度下降使用adagrad更新规则
示例
importboltzmanncleanimportnumpyasnpimportpandasaspdfromsklearnimportdatasetsiris=datasets.load_iris()df_iris=pd.DataFrame(iris.data,columns=iris.feature_names)df_iris['target']=pd.Series(iris.target,dtype=str)df_iris.head()
_ | sepal length (cm) | sepal width (cm) | petal length (cm) | petal width (cm) | target |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | 0 |
1 | 4.9 | 3.0 | 1.4 | 0.2 | 0 |
2 | 4.7 | 3.2 | 1.3 | 0.2 | 0 |
3 | 4.6 | 3.1 | 1.5 | 0.2 | 0 |
4 | 5.0 | 3.6 | 1.4 | 0.2 | 0 |
添加一些噪音:
noise=[(0,1),(2,0),(0,4)]fornoisyinnoise:df_iris.iloc[noisy]=Nonedf_iris.head()
_ | sepal length (cm) | sepal width (cm) | petal length (cm) | petal width (cm) | target |
---|---|---|---|---|---|
0 | 5.1 | NaN | 1.4 | 0.2 | None |
1 | 4.9 | 3.0 | 1.4 | 0.2 | 0 |
2 | NaN | 3.2 | 1.3 | 0.2 | 0 |
3 | 4.6 | 3.1 | 1.5 | 0.2 | 0 |
4 | 5.0 | 3.6 | 1.4 | 0.2 | 0 |
清除数据框:
df_iris_cleaned=boltzmannclean.clean(dataframe=df_iris,numerical_columns=['sepal length (cm)','sepal width (cm)','petal length (cm)','petal width (cm)'],categorical_columns=['target'],tune_rbm=True)df_iris_cleaned.round(1).head()
_ | sepal length (cm) | sepal width (cm) | petal length (cm) | petal width (cm) | target |
---|---|---|---|---|---|
0 | 5.1 | 3.3 | 1.4 | 0.2 | 0 |
1 | 4.9 | 3.0 | 1.4 | 0.2 | 0 |
2 | 6.3 | 3.2 | 1.3 | 0.2 | 0 |
3 | 4.6 | 3.1 | 1.5 | 0.2 | 0 |
4 | 5.0 | 3.6 | 1.4 | 0.2 | 0 |
数据集越大,相关性越强,估算值就越好。