Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
neuralMexicanStateClassifier/keras1.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (32 sloc)
1.22 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import pickle | |
from pathlib import Path | |
print("-------------start-------------") | |
# For reproducibility | |
np.random.seed(1237) | |
# Source file directory | |
path_data = "U:/data/" | |
fn_train = "train.csv" #"filewos_bib_random_nastates.csv" | |
trainingdata = pd.read_csv(path_data + fn_train, usecols=['CITY', 'INSTITUTION_FULL','ADDRESS_FULL','d_state']) #,'OBSERVATION' | |
print(trainingdata.head(20)) | |
print("-------------1.0-------------") | |
print(trainingdata[0:20]) | |
files_train = skds.load_files(path_train,load_content=False) | |
from keras.preprocessing.text import Tokenizer | |
from keras.models import Sequential | |
from keras.layers import Activation, Dense, Dropout | |
#from sklearn.preprocessing import LabelBinarizer | |
#import sklearn.datasets as skds | |
label_index = files_train.target | |
label_names = files_train.target_names | |
labelled_files = files_train.filenames | |
data_tags = ["filename","category","news"] | |
data_list = [] | |
# Read and add data from file to a list | |
i=0 | |
for f in labelled_files: | |
data_list.append((f,label_names[label_index[i]],Path(f).read_text())) | |
i += 1 | |
# We have training data available as dictionary filename, category, data | |
data = pd.DataFrame.from_records(data_list, columns=data_tags) |