# Load data set
df = pd.read_csv("./HTRU_2.csv", hearer=None)
X = df.iloc[:, :-1]
y = df.iloc[:, -1:].values

# Normalization
normalizer = StandardScaler()
X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    test_size=0.3,
                                                    stratify=y,
                                                    random_state=42)
X_train = normalizer.fit_transform(X_train)
X_test = normalizer.transform(X_test)
X_train, y_train = preprocess.upsampling(X_train, y_train, ratio=1 / 5)

# Train model with fine-tuned parameters
lr = LogisticRegression(solver='liblinear',
                        penalty='l1',
                        tol=0.0001,
                        C=0.1,
                        n_jobs=-1,
                        random_state=95)
clf_lr = lr.fit(X_train, y_train)

# Cross validation
cv = ShuffleSplit(n_splits=5, test_size=0.3, random_state=95)
res = {}
for scoring in ('f1', 'roc_auc', 'precision', 'recall'):
    res[scoring] = cross_val_score(clf_lr,
Пример #2
0
# coding=utf-8
# Author = 'QQ'

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import preprocess
audio_path = '3.mp3'
action_path = '3.csv'
mfcc = preprocess.mff_extract(audio_path)
actions = preprocess.upsampling(action_path)
action_frame = preprocess.actions_frame(actions)
action_filled = np.pad(action_frame,
                       ((0, mfcc.shape[0] - action_frame.shape[0]), (0, 0)),
                       'edge')
sample = np.hstack([mfcc, action_filled])
np.savetxt('3.txt', sample)
sample = np.loadtxt('3.txt')
# 以上为数据预处理代码

actions.to_csv('actions.csv')
action_frame = pd.DataFrame(action_frame.T)
action_frame.to_csv('action_frame.csv')

# stft detail

# By default, use the entire frame

win_length = n_fft
window = 'hann'
dtype = np.complex64