you can use sklearn's built-in tool:

from sklearn.externals import joblib
scaler_filename = "scaler.save"
joblib.dump(scaler, scaler_filename) # And now to load... scaler = joblib.load(scaler_filename)

注意: from sklearn.preprocessing import MinMaxScaler 中的 MinMaxScaler 只接受shape为 [n, 1] 的数据的缩放, [1, n]的shape的数据是不能缩放的(缩放所得数据会出错):

https://stackoverflow.com/questions/25886116/sklearns-minmaxscaler-only-returns-zeros

问题:

I am trying to scale a some number to a range of 0 - 1 using preprocessing from sklearn. Thats what i did:

data = [44.645, 44.055, 44.54, 44.04, 43.975, 43.49, 42.04, 42.6, 42.46, 41.405]
min_max_scaler = preprocessing.MinMaxScaler(feature_range=(0, 1))
data_scaled = min_max_scaler.fit_transform([data])
print data_scaled

But data_scaled only contains zeros. What am i doing wrong?

回答:

I had the same problem when I tried scaling with MinMaxScaler from sklearn.preprocessing. Scaler returned me zeros when I used a shape a numpy array as list, i.e. [1, n]. Input array would looked in your case like

data = [[44.645, 44.055, 44.54, 44.04, 43.975, 43.49, 42.04, 42.6, 42.46, 41.405]]

I changed the shape of array to [n, 1]. I your case it would be

data = [[44.645],
[44.055],
[44.540],
[44.040],
[43.975],
[43.490],
[42.040],
[42.600],
[42.460],
[41.405]]

Then MinMaxScaler worked in proper way.

How to store scaling parameters for later use的更多相关文章

  1. 断句:Store all parameters but the first passed to this function as an array

    // Store all parameters but the first passed to this function as an array //除了第一个参数,把调用publish函数时的所有 ...

  2. PHP7函数大全(4553个函数)

    转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...

  3. windows下使用libsvm3.2

    一.官方介绍 libsvm主页:https://www.csie.ntu.edu.tw/~cjlin/libsvm/index.html libsvm介绍文档:http://www.csie.ntu. ...

  4. libsvm下的windows版本中的工具的使用

    下载的libsvm包里面已经为我们编译好了(windows).进入libsvm\windows,可以看到这几个exe文件: a.svm-toy.exe:图形界面,可以自己画点,产生数据等. b.svm ...

  5. 微软版的SqlHelper.cs类

    一,微软SQLHelper.cs类 中文版: using System; using System.Data; using System.Xml; using System.Data.SqlClien ...

  6. OracleHelper类

    using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...

  7. SqlHelper类

    using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...

  8. 【2016-11-2】【坚持学习】【Day17】【微软 推出的SQLHelper】

    从网络上找到 微软原版本的SQLHelper,很多行代码.认真看了,学习了.  代码:  using System; using System.Data; using System.Xml; usin ...

  9. SqlHelper c#

    using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collect ...

随机推荐

  1. Spring Boot可以离开Spring Cloud独立使用开发项目,但是Spring Cloud离不开Spring Boot,属于依赖的关系。

    Spring Boot 是 Spring 的一套快速配置脚手架,可以基于Spring Boot 快速开发单个微服务,Spring Cloud是一个基于Spring Boot实现的云应用开发工具:Spr ...

  2. css字体属性相关。

    出处:CSS 参考手册    http://www.w3school.com.cn/cssref/index.asp text-decoration 属性 说明:这个属性允许对文本设置某种效果,如加下 ...

  3. Spring HttpIvoker实现Java的远程调用

    Spring HttpInvoker一种JAVA远程方法调用框架实现,使用的是HTTP协议,允许穿透防火墙,使用JAVA系列化方式,但仅限于Spring应用之间使用,即调用者与被调用者都必须是使用Sp ...

  4. Java8:使用 Optional 处理 null

    写过 Java 程序的同学,一般都遇到过 NullPointerException :) —— 为了不抛出这个异常,我们便会写如下的代码: User user = getUserById(id); i ...

  5. Java 执行linux scp 远程获取文件和上传

      需要的jar包:ganymed-ssh2-build210.jar import java.io.ByteArrayOutputStream;import java.io.File;import ...

  6. Python pycurl使用

    pycurl的学习 (2013-09-26 10:40:31) 转载▼   分类: python pycurl的使用 pycurl是curl的一个python版本. pycurl的使用说明: pycu ...

  7. MathType中怎么设置字体默认颜色

    MathType功能非常强大,在编辑公式时使用非常方便.利用MathType破解版不仅可以改变公式的字体和字号,也可以改变公式字体颜色.有时在编辑完成后需要对MathType公式格式全部进行修改,这时 ...

  8. OSG简单测试框架

    #include <osgDB/ReadFile> #include <osgDB/FileUtils> #include <osg/ArgumentParser> ...

  9. configChanges

    android中的组件Activity在manifest.xml文件中可以指定参数android:ConfigChanges,用于捕获手机状态的改变. 在Activity中添加了android:con ...

  10. c#基础 第二讲

    判断一个人的体重是否为标准体重 计算公式:男生:体重(kg)-身高+100=±3(在此范围内为标准体重) 女生:体重(kg)-身高+110=±3 using System; using System. ...