欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python基础技巧(四)——sklearn

程序员文章站 2022-06-12 22:50:22
...
  • **函数
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.

相关标签: sklearn