# construct our data dictionary which maps the data types of the
# columns in the CSV file to built-in data types
print("[INFO] building column names...")
types = {"feat_{}".format(i): float for i in range(0, args["cols"])}
types["class"] = int

# create a CSV data generator for the extracted Keras features
dataset = stream.iter_csv(args["csv"], target_name="class", types=types)

# construct our pipeline
model = Pipeline([
    ("scale", StandardScaler()),
    ("learn", OneVsRestClassifier(binary_classifier=LogisticRegression()))])

# initialize our metric
print("[INFO] starting training...")
metric = Accuracy()

# loop over the dataset
for (i, (X, y)) in enumerate(dataset):
    # make predictions on the current set of features, train the
    # model on the features, and then update our metric
    preds = model.predict_one(X)
    model = model.fit_one(X, y)
    metric = metric.update(y, preds)
    print("INFO] update {} - {}".format(i, metric))

# show the accuracy of the model
print("[INFO] final - {}".format(metric))
Exemple #2
0
    required=True,
    help='Number of columns in the feature CSV file (excluding label).')
arguments = vars(argument_parser.parse_args())

print('[INFO] Building column names...')
types = {f'feature_{i}': float
         for i in range(arguments['num_cols'])}  # Data type per feature
types['class'] = int

dataset = stream.iter_csv(arguments['train'], target_name='class', types=types)

model = Pipeline([('scaler', StandardScaler()),
                  ('learner',
                   OneVsRestClassifier(binary_classifier=PAClassifier()))])

metric = Accuracy()

print('[INFO] Training started...')
for index, (X, y) in enumerate(dataset):
    try:
        predictions = model.predict_one(X)
        model = model.fit_one(X, y)
        metric = metric.update(y, predictions)

        if index % 10 == 0:
            print(f'[INFO] Update {index} - {metric}')
    except OverflowError as e:
        print(f'Overflow error. Skipping metric update for {index}')

print(f'[INFO] Final - {metric}')
Exemple #3
0
engine = create_engine('mysql+pymysql://root:@localhost/tez')

session = 41
query = "select * from elderly_sensor where session = "+str(session)+" order by 'time(second)'"
df = pandas.read_sql(query, engine)
df = df.drop("index", axis=1)
timeList = list(df["time(second)"])

df = df.drop("time(second)", axis=1)

x = df.drop("class", axis=1).to_dict(orient="row")
y = list(df["class"])

metrics = (
    MSE(), 
    Accuracy()
    )

model = (
     StandardScaler() |
     DecisionTreeClassifier()
)

# Mse Accuracy Real
outputfile = open('C:\\Users\\YigitCan\\Desktop\\Tez-Workspace\\Real-Time-Big-Data-Analytics\\Elderly Sensor\\Output'+str(session)+'.txt', 'w')



previous_time = 0.0
for row, target, time_passed in zip(x, y, timeList):
    time_range = time_passed - previous_time
session = 60
#query = "select * from elderly_sensor where session = "+str(session)+" order by 'time(second)'"
query = "select * from elderly_sensor"

df = pandas.read_sql(query, engine)
#logging.info("Data retrieved by Session = " + str(session))
logging.info("Data retrieved by all")
df = df.drop("index", axis=1)
timeList = list(df["time(second)"])

df = df.drop("time(second)", axis=1)

x = df.drop("class", axis=1).to_dict(orient="row")
y = list(df["class"])

acc = Accuracy()
fbeta = MultiFBeta(betas=({1: 0.5, 2: 0.5, 3: 0.5, 4: 0.5}))

model = (StandardScaler() | DecisionTreeClassifier())
logging.info("Initial model created")
# Mse Accuracy Real
recordNumber = len(y)
text = ""
previous_time = 0.0
logging.info("Learning process has been started")
startTime = time.time()
for row, target, time_passed in tqdm.tqdm(zip(x, y, timeList)):
    '''
    time_range = time_passed - previous_time
    
    if time_range > 0.0: