コード例 #1
0
def main():
    if len(sys.argv) == 3:
        database_filepath, model_filepath = sys.argv[1:]
        print('Loading data...\n    DATABASE: {}'.format(database_filepath))
        X, Y, category_names = load_data(database_filepath)
        X_train, X_test, Y_train, Y_test = train_test_split(X,
                                                            Y,
                                                            test_size=0.2)

        print('Building model...')
        model = model_pipeline_v2()

        print('Training model...')
        model.fit(X_train, Y_train)

        print('Evaluating model...')
        evaluate_model(model, X_test, Y_test, category_names)

        print('Saving model...\n    MODEL: {}'.format(model_filepath))
        save_model(model, model_filepath)
コード例 #2
0
from models.train_classifier import load_data
from models.train_classifier import load_model
from figures.figures import return_data_figures
from figures.figures import return_result_figures

# Handle user input
if len(sys.argv) == 3:
    database_filepath, model_filepath = sys.argv[1:]
else:
    database_filepath = '../data/disaster_response.db'
    model_filepath = '../models/model.pickle'

app = Flask(__name__)

# Load training data
_, Y, category_names = load_data(database_filepath, TRAIN_TABLE_NAME)

# Load model
model = load_model(model_filepath)

# Load document-term matrix
X_term = sp.load_npz('../models/' + DOCUMENT_TERM_MATRIX_NAME)


# Index webpage displays cool visuals and receives user input text for model
@app.route('/')
@app.route('/index')
def index():

    # Return plotly graphs for visualization
    graphs = return_data_figures(X_term, Y, model)
from models.train_classifier import evaluate_model, load_data, tokenize
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
from pandas import DataFrame
import joblib

model = joblib.load("../models/classifier.pkl")
database_filepath = '../data/DisasterResponse.db'
X, Y, category_names = load_data(database_filepath)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)

Y_pred = DataFrame(data=model.predict(X_test.head(10)), columns=category_names)
evaluate_model(model, X_test.head(10), Y_test.head(10), category_names)
コード例 #4
0
    global _pipe
    return _pipe.transform(np.array([text]))


def apply_model(x_transformed):
    global _clf1, _clf2
    labels_zuordnung_mlp = _clf1.classes_
    y_pred_mlp_proba = _clf1.predict_proba(x_transformed)
    y_pred_mlp_label = np.array(
        [labels_zuordnung_mlp[np.argmax(t)] for t in y_pred_mlp_proba])
    y_pred_moc_labels = np.array(_clf2.predict(x_transformed))
    return y_pred_mlp_label, y_pred_moc_labels


# load data
DATA, Y, target = tc.load_data("./data/DisasterResponse.db")
Y = pd.DataFrame(Y)
Y.columns = target

# load model
load_model("./data/rodelbahn_model.pckl")


def show_example():
    t = pd.Series(DATA).sample()
    print(t.iloc[0])
    print(Y.iloc[int(t.index[0])].to_dict())


# index webpage displays 2 visuals and receives user input text for model's prediction
@app.route('/')
コード例 #5
0
from numpy import log
from numpy.random import random
from wordcloud import WordCloud, STOPWORDS

from models.train_classifier import load_data

####################################################################################################
# Initialization                                                                                   #
####################################################################################################

# Load External Dependencies #######################################################################

with open('models/model.pkl', 'rb') as f:
    classifier = pickle.load(f)

X, y, cat_names = load_data('data/udacity.db')

cat_counts = {cat: y[:, inx].sum() for inx, cat in enumerate(cat_names)}

####################################################################################################
# Category Display                                                                                 #
####################################################################################################


def gen_cat_card(cat):
    '''Generates an html element to display one of the categories which a message has
    been tagged with'''

    # Format for display
    cat = cat.replace('_', ' ')
    cat = cat.title()