python基础技巧(四)——sklearn

  • 激活函数
tf.sigmoid(x)
tf.tanh(x)
tf.softsign(x)
tf.nn.relu(x)
tf.nn.elu(x)
tf.nn.bias_add(values,bias)
  • 损失优化方法
    • tf.train.
tf.train.GradientDescentOptimizer(learning_rate=,use_locking=,name=)
tf.train.AdadeltaOptimizer(learning_rate=,use_locking=,name=)
tf.train.AdagradOptimizer(learning_rate=,use_locking=,name=)
tf.train.AdamOptimizer(learning_rate=,use_locking=,name=)
...

数据预处理——标准化,均值去除和按方差比例缩放(Standardization, or mean removal and variance scaling)

  • StandardScaler计算训练集的平均值和标准差,以便测试数据集使用相同的变换。

  • scale 零均值单位方差

    • 1)若设置with_mean=False 或者 with_std=False,则不做centering 或者scaling处理。

      2)scale和StandardScaler可以用于回归模型中的目标值处理。

  • MinMaxScaler(最小最大值标准化)

  • MaxAbsScaler(绝对值最大标准化)

各种误差

from sklearn import metrics
metrics.mean_absolute_error(Y_predict,Y_true)
metrics.mean_squared_error(Y_predict,Y_true)
metrics.mean_squared_log_error(Y_predict,Y_true)
metrics.median_absolute_error(Y_predict,Y_true)
...
  • cross_validation

    将数据集拆分为训练集和测试集

    • train_size=0.7 表示训练集占全集的70%
    • test_size=0.2 表示测数据占全集的20%
cross_validation.train_test_split(X,y,train_size=0.7,test_size=0.2)
  • sklearn.utils.shuffle

随机排序

*arrays : sequence of indexable data-structures

Indexable data-structures can be arrays, lists, dataframes or scipy sparse matrices with consistent first dimension.

random_state : int, RandomState instance or None, optional (default=None)

The seed of the pseudo random number generator to use when shuffling the data. If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

n_samples : int, None by default

Number of samples to generate. If left to None this is automatically set to the first dimension of the arrays.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值