Categorical Embedder是一个python包,允许您通过神经网络将分类变量转换为数字
categorical-embedder的Python项目详细描述
范畴嵌入
Categorical Embedder是一个python包,它允许您通过神经网络将分类变量转换为数值
安装
pip install categorical_embedder
示例
importcategorical_embedderascefromsklearn.model_selectionimporttrain_test_splitdf=pd.read_csv('HR_Attrition_Data.csv')X=df.drop(['employee_id','is_promoted'],axis=1)y=df['is_promoted']embedding_info=ce.get_embedding_info(X)X_encoded,encoders=ce.get_label_encoded_data(X)X_train,X_test,y_train,y_test=train_test_split(X_encoded,y)embeddings=ce.get_embeddings(X_train,y_train,categorical_embedding_info=embedding_info,is_classification=True,epochs=100,batch_size=256)
更详细的Jupyter Notebook可以在这里找到
What's inside Categorical Embedder ?
ce.get_embedding_info(data,categorical_variables=None)
:此函数标识数据中的所有分类变量,确定其嵌入大小。分类变量的嵌入大小由其唯一值个数的至少50个或一半来确定,即列的嵌入大小=Min(该列中的唯一值为50个) 可以在categorical_variables
参数中传递明确的分类变量列表。如果None
,此函数将自动获取数据类型为object
的所有变量ce.get_label_encoded_data(data, categorical_variables=None)
:此函数标签使用sklearn.preprocessing.LabelEncoder并返回用于训练的标签编码数据帧。深度学习lib库或任何其他深度学习库都希望数据是这种格式的。在ce.get_embeddings(X_train, y_train, categorical_embedding_info=embedding_info, is_classification=True, epochs=100,batch_size=256)
:这个函数训练一个浅层神经网络并返回类别变量的嵌入。在引擎盖下,它是一个2层的神经网络结构,有1000个和500个具有“ReLU”激活的神经元。它需要4个必需的输入-X_train
,y_train
,categorical_embedding_info
:get_embedding_info函数的输出,is_classification
:True
用于分类任务;False
用于回归任务。在
对于分类:loss = 'binary_crossentropy'; metrics = 'accuracy'
和回归:loss = 'mean_squared_error'; metrics = 'r2'
依赖关系
^{pr2}$- 项目
标签: