码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 顺序编码器--OrdinalEncoder类


    目录

    • OrdinalEncoder
    • 参数
      • categories
      • dtype
      • handle_unknown
      • unknown_value
      • encoded_missing_value
    • 属性
      • categories_
      • n_features_in_
      • feature_names_in_
    • 方法
      • fit(X[, y])
      • fit_transform(X[, y])
      • get_feature_names_out([input_features])
      • get_params([deep])
      • inverse_transform(X)
      • set_params(**params)
      • transform(X)
    • 使用示例

    OrdinalEncoder

    sklearn.preprocessing.OrdinalEncoder(*, categories='auto', dtype=<class 'numpy.float64'>, handle_unknown='error', unknown_value=None, encoded_missing_value=nan)
    
    • 1

    将分类特征转化为整数数组
    编码器的输入应该是以整数或字符串为元素的类数组,表示由分类的(离散的)特征所获得的值,这些特征被转换为序列整数,这将导致每个特征产生一个整数列

    The input to this transformer should be an array-like of integers or strings, denoting the values taken on by categorical (discrete) features. The features are converted to ordinal integers. This results in a single column of integers (0 to n_categories - 1) per feature

    参数

    categories

    ‘auto’ or a list of array-like, default=’auto’

    参数可选值
    auto根据数据选择编码规则
    listcategories[i]保存第i列中期望的类别

    dtype

    number type, default np.float64
    期望的输出数据类型

    handle_unknown

    {‘error’, ‘use_encoded_value’}, default=’error’
    当被设置为error时,当transform过程中遇到未知分类特征时将会抛出一个错误

    unknown_value

    int or np.nan, default=None
    当参数handle_unknown被设置为use_encoded_value时,该参数是必须的

    encoded_missing_value

    int or np.nan, default=np.nan

    缺失类别的编码值。如果设置为np.Nan,那么参数dtype必须是浮点型

    属性

    categories_

    list of arrays
    在拟合过程中确定每个特征的类别

    The categories of each feature determined during fit (in order of the features in X and corresponding with the output of transform). This does not include categories that weren’t seen during fit.

    n_features_in_

    int
    拟合过程中的特征数量

    feature_names_in_

    ndarray of shape (n_features_in_,)

    拟合过程中的特征名称

    Names of features seen during fit. Defined only when X has feature names that are all strings.

    方法

    fit(X[, y])

    拟合数据

    Fit the OrdinalEncoder to X.

    fit_transform(X[, y])

    拟合数据并进行转换

    Fit to data, then transform it.

    get_feature_names_out([input_features])

    返回输出特征名称

    Get output feature names for transformation.

    get_params([deep])

    返回模型参数

    Get parameters for this estimator.

    inverse_transform(X)

    还原数据

    Convert the data back to the original representation.

    set_params(**params)

    设置模型参数

    Set the parameters of this estimator.

    transform(X)

    转换数据为序列代码

    Transform X to ordinal codes.

    使用示例

    from sklearn.preprocessing import OrdinalEncoder
    encoder = OrdinalEncoder()
    x = [['Male', 1], ['Female', 3], ['Female', 2]]
    x_transform=encoder.fit_transform(x)
    x_transform
    >>> array([[1., 0.],
           [0., 2.],
           [0., 1.]])
    encoder.inverse_transform(x_transform)
    >>>array([['Male', 1],
           ['Female', 3],
           ['Female', 2]], dtype=object)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
  • 相关阅读:
    基于三维gis平台的消防系统运用
    GD32测量pwm波频率以及占空比
    猿创征文 |【Ant Design Pro】使用ant design pro做为你的开发模板(六)OpenAPI,快速管理你的请求接口
    用Python订正数据
    阿里开源SpringBoot全栈小册 (建议学习)
    php字符解析json_decode为null
    自托管书签管理器LinkAce
    【校招VIP】java语言考点之双亲委派模型
    计算机毕业设计微信小程序地摊租赁管理平台
    Arduino追光小车
  • 原文地址:https://blog.csdn.net/m0_54510474/article/details/128035414
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号