Tagged: numpy

4,055  2

[TF.7]多类别神经网络

本文参考《Google机器学习速成课程》多类别神经网络点击下载源码 设置 !wget https://storage.googleapis.com/mledu-datasets/mnist_train_small.csv -O /tmp/mnist_train_small.csv import glob import io import math import os from IPython import display from matplotlib import cm from matplotlib import gridspec from matplotlib import pyplot as plt import numpy as np import pandas as pd import seaborn as sns from sklearn import metrics import tensorflow as tf from tensorflow.python.data import Dataset tf.logging.set_verbosity(tf.logging.ERROR) pd.options.display.max_rows = 10 pd.options.display.float_format = ‘{:.1f}’.format mnist_dataframe = pd.read_csv( io.open("/tmp/mnist_train_small.csv", "r"), sep=",", header=None) # Use just the first 10,000 records for training/validation mnist_dataframe = mnist_dataframe.head(10000) mnist_dataframe = mnist_dataframe.reindex(np.random.permutation(mnist_dataframe.index)) training_targets, training_examples = parse_labels_and_features(mnist_dataframe[:7500]) validation_targets, validation_examples = parse_labels_and_features(mnist_dataframe[7500:10000]) seaborn Seaborn是基于matplotlib的python数据可视化库,提供更高层次的API封装,使用起来更加方便快捷。 构造神经网络模型 # Extracts labels and...

2,536  0

Numpy、Pandas语法小记

设置 pd.set_option(‘display.mpl_style’, ‘default’) # Make the graphs a bit prettier #option display.mpl_style providing a sleeker visual style for plots, based on [GH3075][1] pd.set_option(‘display.line_width’, 5000) pd.set_option(‘display.max_columns’, 60) DataFrame df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=[‘A’,’B’,’C’,’D’]) df = pd.read_csv(path_train, encoding="utf-8", header=0) df.to_csv(path,columns=[‘Pred’], index=True, header=True) df.info()#类型 df.describe()#统计 时间转换 data[‘TIME’] = pd.to_datetime(data[‘TIME’], unit=’s’) #将Unix毫秒数据转为datetime格式 data[‘TIME’].astype(‘<M8[ns]’) #转换列类型 data[‘HOUR’] = [i.hour for i in data["TIME"]] #从datetime中取小时 重命名列名 df.index.name = ‘Id’ #重命名索引列 df.columns = [‘Id’, ‘Pred’] #重命名所有列 df.rename(columns={‘Y’:’Pred’}, inplace = True) #重命名指定列 选取DataFrame信息 #取列 df[‘A’]#得到Series类型 df[[‘A’,’B’]]#得到DataFrame类型 #取行 df.loc[100],df.ix[100] #按index值取Series df.iloc[0] #按位置选Series df.loc[[100,101,102]],df.loc[100:103] df.iloc[[0,1,2]],df.iloc[0:3] #取值 df.loc[100][‘A’],df.loc[100,’A’]#float64 df.loc[100,[‘A’]],df.ix[100:102,[‘A’,’B’]]#Series/DataFrame df.iloc[0][‘A’]#取值 df.iloc[0:2][[‘A’,’B’]]#取值