- 一、添加模板文件
- 二、显示效果
latex模板文件中对应添加下列内容
documentclass{article} usepackage{listings} usepackage{xcolor} definecolor{codegreen}{rgb}{0,0.6,0} definecolor{codegray}{rgb}{0.5,0.5,0.5} definecolor{codepurple}{rgb}{0.58,0,0.82} definecolor{backcolour}{rgb}{0.95,0.95,0.92} lstdefinestyle{mystyle}{ backgroundcolor=color{backcolour}, commentstyle=color{codegreen}, keywordstyle=color{magenta}, numberstyle=tinycolor{codegray}, stringstyle=color{codepurple}, basicstyle=ttfamilyfootnotesize, breakatwhitespace=false, breaklines=true, captionpos=b, keepspaces=true, numbers=left, numbersep=5pt, showspaces=false, showstringspaces=false, showtabs=false, tabsize=2 } lstset{style=mystyle} begin{document} %% 下面为具体代码 begin{lstlisting}[language=Python, caption= DataGen] def gen_datas(train, test): """生成数据 参数: train: 原始训练数据集 test: 原始验证数据集 返回: X_train_r: 处理后训练数据集 y_train: 处理后训练标签 X_test_r: 处理后验证数据集 y_test: 处理后验证标签 """ label_encoder_train = LabelEncoder().fit(train.Result) labels_train = label_encoder_train.transform(train.Result) label_encoder_test = LabelEncoder().fit(test.Result) labels_test = label_encoder_test.transform(test.Result) classes = list(label_encoder_train.classes_) # classes_test = list(label_encoder_test.classes_) train = train.drop('Result', axis=1) test = test.drop('Result', axis=1) # 标签的种类 = NB_CLASS numb_class = len(classes) # 数据的归一化处理 scaled_train = data_scaler(train) # 同一文件内数据集:10%作为测试集,90%作为训练集 # random_state:随机数种子,和random中的seed种子一样,保证每次抽样到的数据一样,便于调试 sss = StratifiedShuffleSplit(test_size=0.1, random_state=23) for train_index, test_index in sss.split(scaled_train, labels_train): X_train, X_test = scaled_train[train_index], scaled_train[test_index] y_train, y_test = labels_train[train_index], labels_train[test_index] # 不同文件作为训练集和验证集 # y_train = labels_train # X_train = data_scaler(train) # y_test = labels_test # X_test = data_scaler(test) # reshape train data # reshape 30*1 # 也可以reshape 10*3 X_train_r = np.zeros((len(X_train), NB_FEATURES, 1)) X_train_r[:, :, 0] = X_train[:, :NB_FEATURES] # X_train_r[:, :, 1] = X_train[:, NB_PER_LAYER: NB_PER_LAYER * 2] # X_train_r[:, :, 2] = X_train[:, NB_PER_LAYER * 2:] # reshape test data X_test_r = np.zeros((len(X_test), NB_FEATURES, 1)) X_test_r[:, :, 0] = X_test[:, :NB_FEATURES] # X_test_r[:, :, 1] = X_test[:, NB_PER_LAYER: NB_PER_LAYER * 2] # X_test_r[:, :, 2] = X_test[:, NB_PER_LAYER * 2:] y_train = np_utils.to_categorical(y_train, NB_CLASS) y_test = np_utils.to_categorical(y_test, NB_CLASS) return X_train_r, y_train, X_test_r, y_test end{lstlisting} %% end{document}二、显示效果
具体效果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)