02 python 学习

来源:互联网 发布:淘宝联盟软件 编辑:程序博客网 时间:2024/05/16 23:35


这里主要讲解 argsort 排序这个函数,
来源于:numpy.argsort
pandas继承于numpy:pandas.Series.argsort


from sklearn.model_selection import train_test_split#这里train_test_split返回的都是<class 'pandas.core.series.Series'>x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=1, train_size=0.8)order = y_test.argsort(axis=0)#获取顺序print('type of order:', type(order))print('content of order:', order)print('type of y_test: ',type(y_test))print('y test before sort:',y_test)y_test = y_test.values[order]#对y_test进行排序print('y test after sort:', y_test)#对x_test进行排序,由于x_test为矩阵,所以使用[order,:]x_test = x_test.values[order, :]


原创粉丝点击