scikit-learn杂记
1.数据预处理 二值化
import numpy as np
from sklearn import preprocessing X = np.array([[1., -1., 2.], [2., 0., 0.], [0., 1., -1.]])
binarized = preprocessing.Binarizer().fit(X)
print(binarized.transform(X))
2.数据预处理 Onehot处理离散数据
import numpy as np
from sklearn import preprocessing Y = np.array([[0, 1, 0], [1, 0, 1], [2, 2, 1], [3, 1, 0]])
enc = preprocessing.OneHotEncoder()
enc.fit(Y)
print(enc.transform([[3, 0, 1]]).toarray())
3.综合处理文本离散数据 Onehot处理离散文本数据
import numpy as np
from sklearn import preprocessing
from sklearn.preprocessing import LabelEncoder # 原始离散数据,其中国家有四种数据,职业有三种数据,性别有两种数据,即[2,3,4]
Y_label = np.array([['from China', 'Student', 'Male'], ['from USA', 'Teacher', 'Female'],
['from UK', 'Engineer', 'Female'],['from AU', 'Student', 'Male']]) # 将离散文本转换为数字表示
le_from = LabelEncoder()
le_job = LabelEncoder()
le_gender = LabelEncoder()
le_from.fit(np.array(['from China', 'from USA', 'from UK', 'from AU']))
le_job.fit(np.array(['Student', 'Teacher', 'Engineer']))
le_gender.fit(np.array(['Male','Female'])) # 替换原数据
Y_label[:, 0] = le_from.transform(Y_label[:, 0])
Y_label[:, 1] = le_job.transform(Y_label[:, 1])
Y_label[:, 2] = le_gender.transform(Y_label[:, 2]) # 使用OneHot编码数据
enc = preprocessing.OneHotEncoder()
enc.fit(Y_label)
print(enc.transform([[3, 0, 1]]).toarray())
scikit-learn杂记的更多相关文章
- scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类 (python代码)
scikit learn 模块 调参 pipeline+girdsearch 数据举例:文档分类数据集 fetch_20newsgroups #-*- coding: UTF-8 -*- import ...
- (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探
一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...
- (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探
目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...
- Scikit Learn: 在python中机器学习
转自:http://my.oschina.net/u/175377/blog/84420#OSC_h2_23 Scikit Learn: 在python中机器学习 Warning 警告:有些没能理解的 ...
- Scikit Learn
Scikit Learn Scikit-Learn简称sklearn,基于 Python 语言的,简单高效的数据挖掘和数据分析工具,建立在 NumPy,SciPy 和 matplotlib 上.
- Linear Regression with Scikit Learn
Before you read This is a demo or practice about how to use Simple-Linear-Regression in scikit-lear ...
- 如何使用scikit—learn处理文本数据
答案在这里:http://www.tuicool.com/articles/U3uiiu http://scikit-learn.org/stable/modules/feature_extracti ...
- Query意图分析:记一次完整的机器学习过程(scikit learn library学习笔记)
所谓学习问题,是指观察由n个样本组成的集合,并根据这些数据来预测未知数据的性质. 学习任务(一个二分类问题): 区分一个普通的互联网检索Query是否具有某个垂直领域的意图.假设现在有一个O2O领域的 ...
- 机器学习框架Scikit Learn的学习
一 安装 安装pip 代码如下:# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=83 ...
- Python第三方库(模块)"scikit learn"以及其他库的安装
scikit-learn是一个用于机器学习的 Python 模块. 其主页:http://scikit-learn.org/stable/. GitHub地址: https://github.com/ ...
随机推荐
- QComboBox实现复选功能(三种方法:嵌套QListWidget, 设置QStandardItemModel, 设置Delegate)
今天介绍一下一个小东西 — 如何让QComboBox实现复选功能? 需求: 下拉列表有复选功能 不可编辑 显示所有选中项 关于QComboBox的复选功能有几种方案: QStandardIte ...
- 给WPF示例图形加上方便查看大小的格子之完善版本
原文:给WPF示例图形加上方便查看大小的格子之完善版本 去年10月份, 我曾写过一篇"给WPF示例图形加上方便查看大小的格子"的BLOG(http://blog.csdn.net/ ...
- 简明Python3教程 16.标准库
简介 python标准库作为python标准安装的一部分,其自身包含数量庞大的实用模块, 因此熟悉python标准库非常重要,因为很多问题都能利用python标准库快速解决. 下面我们将研究标准库中的 ...
- 首个 C++ 编译器诞生 30 周年了,来听听 C++ 之父畅谈 C++
原文 http://www.iteye.com/news/31076 C++ 之父 Bjarne Stroustrup 在 cfront 诞生 30 周年的访谈. 整整30年前,CFront 1 ...
- js 指向表格行变色,离开恢复
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- WPF 元素tag属性绑定一个属性或一个对象
<Window x:Class="CollectionBinding.CategoryDataTemp" xmlns="http://schemas. ...
- MVC 调试路由
1.添加引用RouteDebug.dll 2 修改Global.asax,切记调试过后要删掉 using System;using System.Collections.Generic;using S ...
- c# 安装windows服务
C# windows服务: 第一种 :通过cmd命令安装.卸载.启动和停止Windows Service(InstallUtil.exe) 步骤: 1.运行--〉cmd:打开cmd命令框 2.在命令行 ...
- 图像滤镜艺术---球面(Spherize)滤镜
原文:图像滤镜艺术---球面(Spherize)滤镜 球面(Spherize)滤镜 球面滤镜是通过极坐标变换实现图像的球面特效. 代码如下: // /// ...
- C#从列表中取元素的某个字段组成新的列表
using System; using System.Collections.Generic; using System.Linq; namespace CSharpDemo { class Prog ...