# -*- coding: utf-8 -*-
"""
Created on Wed Jun 14 15:17:36 2017
训练分类器
@author: baishuhua
"""
import warnings
warnings.filterwarnings('ignore')
import time
import os
import Extraction_DTFT as Ext
import numpy as np
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split,cross_val_score,GridSearchCV
from sklearn.svm import SVC
from sklearn.dummy import DummyClassifier
from sklearn.pipeline import Pipeline
random_state=np.random.seed()
import pickle
import sys;sys.path.append('E:\\大数据')
import sampler
from collections import Counter
# ******************** 装载已构建特征集 ******************** #
def DataSet(file):
Data=pd.read_csv(file,encoding='gbk',na_values=['#NAME?','inf','INF','-inf','-INF'])
Featurename=Data.columns.values[2:]
Data=Data.dropna(how='all',axis=0,subset=Featurename)
Data=Data.fillna(axis='index',method='pad')
Feature=Data[Featurename].values
Filename=Data['Filename'].values
Label=Data['Label'].values
return Filename,Featurename,Feature,Label
# ******************** 剔除异常样本 ******************** #
def RemoveAbnormal(BigFeatures,contamination = 0.05):
print('******************** 剔除异常样本 ********************\n')
from sklearn import ensemble
clf = ensemble.IsolationForest(max_samples='auto', contamination=contamination, \
max_features=1.0, bootstrap=False, random_state=42)
clf.fit(BigFeatures)
y_detection=clf.predict(BigFeatures)
mask = (y_detection==-1)
return mask # 异常样本编号
def Encoding(Label):
Encoder=preprocessing.LabelEncoder().fit(Label)
return Encoder
# ******************** 标准化处理特征集 ******************** #
def Scaler():
scaler=preprocessing.MaxAbsScaler(copy=True)
return scaler
# ******************** 模型评估 ******************** #
from sklearn.metrics import make_scorer
from sklearn.metrics import accuracy_score,f1_score,fbeta_score,jaccard_similarity_score,precision_score,recall_score # 该类指标越大性能越好
from sklearn.metrics import hamming_loss,zero_one_loss # 该类指标绝对值越小性能越好
def Evaluate(score_func=accuracy_score):
if score_func in [accuracy_score,f1_score,fbeta_score,jaccard_similarity_score,precision_score,recall_score]:
greater_is_better=True
elif score_func in [hamming_loss,zero_one_loss]:
greater_is_better=False
score=make_scorer(score_func=score_func,greater_is_better=greater_is_better,needs_proba=False,needs_threshold=False,average='micro')#
return score
# 混淆矩阵可视化预测结果
import itertools
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
def plot_confusion_matrix(cm,classes,normalize=False,title='Confusion matrix',cmap=plt.cm.Blues):
"""
This function prints and plots the confusion matrix.
Normalization can be applied by setting `normalize=True`.
"""
np.set_printoptions(precision=2)
plt.figure(figsize=(12,6))
plt.imshow(cm,interpolation='nearest', cmap=cmap)
plt.title(title)
plt.colorbar()
tick_marks=np.arange(len(classes))
plt.xticks(tick_marks,classes,rotation=45)
plt.yticks(tick_marks,classes)
if normalize:
cm=cm.astype('float')/(cm.sum(axis=1)[:,np.newaxis]+1e-10)
print("Normalized confusion matrix")
else:
print('Confusion matrix, without normalization')
print(cm)
thresh=cm.max()/ 2.
for i,j in itertools.product(range(cm.shape[0]), range(cm.shape[1])): # itertools.product笛卡尔积 代表两层(嵌套循环)
plt.text(j,i,round(cm[i,j],2),horizontalalignment="center",color="white" if cm[i,j]>thresh else "black")
plt.tight_layout()
plt.ylabel('真实标签') # True label
plt.xlabel('预测标签') # Predicted label
# 可视化二分类器的ROC曲线,并计算曲线积分面积
def Plot_ROC_binary(ys_true,ys_scores,view):
y_true=ys_true;y_score=ys_scores
fpr,tpr,thresholds=roc_curve(y_true,y_score,pos_label=None,sample_weight=None,drop_intermediate=True)
area=auc(fpr,tpr,reorder=False)
if view:
plt.figure()
plt.plot(fpr,tpr,label='ROC and AUC is %.2f' %area)
plt.legend(loc='lower right')
plt.xlim([0.0,1.0]);plt.ylim([0.0,1.1])
plt.xlabel('假正类');plt.ylabel('真正类')
plt.title('ROC曲线')
plt.show()
return area
# 可视化多分类器的ROC曲线,并加权计算曲线积分面积
def Plot_ROC_multi(ys_orig,ys_true,ys_scores,classnames,view):
fpr=dict();tpr=dict();roc_auc=dict()
for i,classname in enumerate(classnames):
y_true=ys_true[:,i];y_score=ys_scores[:,i]
fpr[i],tpr[i],thresholds=roc_curve(y_true,y_score,pos_label=None,sample_weight=None,drop_intermediate=True)
area=auc(fpr[i],tpr[i],reorder=False)
roc_auc[i]=area
# Compute weighted-average ROC curve and ROC area,对于weighted模式,各类的加权系数为各类在总类中的占比
all_fpr=np.unique(np.concatenate([fpr[i] for i in range(len(fpr))]))
# Then interpolate all ROC curves at this points
mean_tpr=np.zeros_like(all_fpr)
from scipy import interp
for i in range(len(classnames)):
mean_tpr += interp(all_fpr,fpr[i],tpr[i])*(sum(ys_orig==i)/len(ys_orig))
# Finally compute AUC
fpr['weighted']=all_fpr;tpr['weighted']=mean_tpr
roc_auc['weighted']=auc(fpr['weighted'],tpr['weighted'])
if view:
plt.figure(figsize=(8,6))
for i,classname in enumerate(classnames):
plt.plot(fpr[i],tpr[i],label=classname+' ROC and AUC is %.2f' %(roc_auc[i]))
plt.plot(fpr['weighted'],tpr['weighted'],label='综合 ROC and AUC is %.2f' %(roc_auc['weighted']))
plt.legend(loc='lower right')
plt.xlim([0.0,1.0]);plt.ylim([0.0,1.1])
plt.show()
return roc_auc['weighted']
if __name__=='__main__':
IsExt = 0
if IsExt:
print('******************** Start extracting features ********************\n')
FilePath = r'E:\大数据\线路故障诊断\解压后数据\广东中调\*.etr-*'
SavePath = r'E:\大数据\线路故障诊断'
SaveFile = '故障整次谐波_三相_gd.csv'
BigSamplenames,BigFeaturenames,BigFeatures,BigLabels = \
Ext.ExtractingAllFile(FilePath,SavePath,SaveFile,SelectCol=[4,5,6])
else:
print('******************** Load extracted features ********************\n')
SavePath = r'E:\大数据\线路故障诊断'
SaveFile = '故障整次谐波_零序_gd.csv'
BigSamplenames,BigFeaturenames,BigFeatures,BigLabels = DataSet(os.path.join(SavePath,SaveFile))
# 装载matlab提取的小波能量均值、标准差和能量熵特征
if 1:
from scipy.io import loadmat
BigFeatures = loadmat(r'E:\大数据\线路故障诊断\XY.mat')['Features'] # 3指标的对数
BigLabels = loadmat(r'E:\大数据\线路故障诊断\XY.mat')['Labels'][0] # 注意数据格式
BigLabels = np.array([element[0] for element in BigLabels])
BigSamplenames = loadmat(r'E:\大数据\线路故障诊断\XY.mat')['Files'][0] # 注意数据格式
BigSamplenames = np.array([element[0] for element in BigSamplenames])
IsRemove = 1
if IsRemove:
mask = RemoveAbnormal(BigFeatures,contamination = 0.05)
print('异常样本类别:\n',BigSamplenames[mask])
Samplenames,Labels,Features = BigSamplenames[~mask],BigLabels[~mask],BigFeatures[~mask,:]
else:
Samplenames,Labels,Features = BigSamplenames,BigLabels,BigFeatures
# 筛选
select = (Labels=='山火') | (Labels=='外力破坏')
Labels = Labels[select]
Features = Features[select]
# 编码
Encoder =
没有合适的资源?快使用搜索试试~ 我知道了~
输电线路故障三相与零序谐波数据,包含外力破坏、山火、异物等情况下的故障数据.rar
共325个文件
etr-9:4个
etr-7:4个
etr-15:4个
2 下载量 102 浏览量
2024-02-29
11:39:38
上传
评论
收藏 42.24MB RAR 举报
温馨提示
输电线路故障三相与零序谐波数据,包含外力破坏、山火、异物等情况下的故障数据.rar
资源推荐
资源详情
资源评论
收起资源包目录
输电线路故障三相与零序谐波数据,包含外力破坏、山火、异物等情况下的故障数据.rar (325个子文件)
故障整次谐波_三相_gd.csv 122KB
故障整次谐波_零序_gd.csv 39KB
对树木放电_对树木放电_1_0_8_国安站侧_20100606国尖乙线_2014年06月06日11时28分47秒.etr-0 1.17MB
异物_2016年07月08日13时16分33秒.etr-0 1.1MB
外力破坏_岗华BH010_CPU1_161103154855005.etr-0 6KB
异物_2016年07月08日13时16分33秒.etr-1 1.1MB
外力破坏_2016-11-03@15-48-55.#F8AACB.etr-1 616KB
对树木放电_对树木放电_1_0_12_柘林电厂_20140720柘苏乙线_2014年07月20日10时56分01秒.etr-1 529KB
风偏_2016-10-21@10-03-15.#13.etr-1 375KB
雷击_雷击_1_0_8_福园站_20140516福鹿乙线_2014-05-16@14-30-04.#30FB.etr-10 961KB
异物_160328114825.etr-10 723KB
外力破坏_2016年05月06日10时11分48秒.etr-10 531KB
鸟害_SSH920.etr-10 143KB
异物_2017年05月30日05时10分08秒.etr-100 514KB
山火_山火_2_0_12_清远局2014年10月18日15时52分-220kV阳旗乙线阳山站侧保护动作情况_20141018阳旗乙线_2014年10月18日15时52分43秒.etr-101 214KB
山火_山火_2_0_20_棉湖站侧_20140121厂棉线相间故障_2014年01月21日15时02分51秒.etr-102 629KB
山火_山火_2_0_20_墨珠甲乙线故障录波屏文件_20140121墨珠甲线_SSH939.etr-103 132KB
山火_山火_2_0_20_墨珠甲乙线故障录波屏文件_20140121墨珠乙线_SSH939.etr-104 133KB
山火_山火_2_0_20_贤令山站_20140123山安甲线_2014年01月23日16时20分50秒.etr-105 627KB
山火_山火_2_0_24_梅县厂侧_20140121厂棉线相间故障_2014年01月21日15时23分01秒.etr-106 292KB
山火_山火_2_0_28_安峰站_20140123山安甲线_SSH793.etr-107 72KB
雷击_雷击_1_0_8_桂山站_20140518桂乐乙线_2014年05月18日10时59分15秒.etr-11 1.16MB
外力破坏_2016年05月06日10时13分52秒.etr-11 879KB
鸟害_2015年06月18日10时33分01秒.etr-11 529KB
异物_160328124003.etr-11 230KB
外力破坏_外力破坏_1_0_12_云浮C厂_20140513云睦乙线_2014年05月13日22时19分54秒.etr-112 2.04MB
外力破坏_外力破坏_1_0_20_睦岗站_20140513云睦乙线_2014年05月13日22时23分21秒.etr-114 537KB
外力破坏_外力破坏_1_0_24_雷州站侧_201407182014雷闻乙线_2014年07月18日19时43分28秒.etr-115 553KB
外力破坏_外力破坏_1_0_28_雷州站侧_201407181826雷闻甲线_2014年07月18日17时55分10秒.etr-116 294KB
外力破坏_外力破坏_1_0_28_雷州站侧_201407181828雷闻甲线(含两次强送)_2014年07月18日17时57分03秒.etr-117 528KB
外力破坏_外力破坏_1_4_12_闻涛站侧_201407181826雷闻甲线_2014y07m18d18h26m38s988ms+act.etr-118 8.85MB
外力破坏_外力破坏_1_4_12_闻涛站侧_201407181828雷闻甲线(含两次强送)_2014y07m18d18h28m32s817ms+act.etr-119 5.76MB
外力破坏_20160601080639.etr-12 1.72MB
雷击_雷击_1_0_8_惠州侧_20140516东惠乙线_2014-05-16@12-02-58.#221.etr-12 972KB
异物_2016-03-28@11-47-52.#31C.etr-12 962KB
鸟害_2015年07月13日14时10分53秒.etr-12 371KB
外力破坏_外力破坏_2_0_24_20:38雷闻乙线故障录波(强送)_201407182038雷闻乙线强送_2014年07月18日20时01分57秒.etr-121 293KB
外力破坏_外力破坏_2_4_16_闻涛站侧_201407182014雷闻乙线_2014y07m18d20h14m57s324ms+act.etr-122 9.25MB
异物_异物_0_0_4_同益站_20140812外同甲线_DGL509.etr-123 769KB
异物_异物_0_0_8_饶平站潮饶录波_20140801潮饶线_140801153653.etr-124 653KB
异物_异物_1_0_4_潮州站_20140817潮饶线_140817170235.etr-126 648KB
异物_异物_1_0_4_潮州站潮饶故障录波_20140801潮饶线_140801153339.etr-127 1.06MB
鸟害_2015-07-13@14-29-37.#1D34.etr-13 1.73MB
异物_2016-03-28_11-47-52_ACT_220kV千秋甲乙~.etr-13 962KB
外力破坏_160601062826.etr-13 714KB
雷击_雷击_1_0_12_能达站_20140509能新线_2014年05月09日18时11分04秒.etr-13 411KB
异物_异物_1_0_4_旺新站_20140917罗旺线_2010年09月17日12时34分04秒.etr-131 370KB
异物_异物_1_0_8_潮阳站侧继电保护动作情况_20141107汕阳线(11点02分)_2014-11-07@11-03-46.#481.etr-133 367KB
异物_异物_1_0_8_热水站_20140814热塔线_2014-08-14_13-06-42_act_220kV录波屏(A0307120254).etr-138 1.26MB
异物_异物_1_0_8_汕头站侧继电保护情况_20141107汕阳线(11点02分)_2014年11月07日11时02分45秒.etr-139 291KB
异物_2016年04月18日00时07分25秒.etr-14 3.7MB
鸟害_2015年07月13日12时53分04秒.etr-14 1.15MB
外力破坏_2016年06月23日14时50分27秒_SSH088.etr-14 351KB
异物_异物_1_0_8_塔岭站_20140814热塔线_2014年08月14日13时06分42秒_SSH710.etr-140 143KB
异物_异物_1_0_8_外海站_20140812外同甲线_140812071824.etr-141 719KB
异物_异物_1_0_12_2014.11.26桂海线继电保护动作情况表_20141126桂海线_2014年11月26日05时31分03秒.etr-142 1.29MB
异物_异物_1_0_16_饶平站_20140817潮饶线_140817170546.etr-143 654KB
异物_异物_1_0_16_仁和站_20140920仁小乙线_2014-09-20_00-42-31_act_fh-3000S.etr-144 4.39MB
异物_异物_1_0_20_500kV罗洞站_20140504罗丹乙线_2014年05月04日14时16分15秒.etr-145 628KB
异物_异物_1_0_20_小榄站_20140920仁小乙线_2014年09月20日00时33分30秒.etr-146 364KB
异物_异物_1_16_8_祯州侧故障录波及保护动作报告_20141027胪祯甲线_500kV第五六串故障录波器2014-10-27-23_43_13-699-00032-05971.etr-147 1.47MB
异物_异物_1_32_28_220kV丹桂站_20140504罗丹乙线_2014年05月04日14时18分13秒.etr-148 298KB
异物_异物_1_48_20_祯侧_20141027胪祯乙线_2014-10-27@23-43-13.#108D0.etr-149 1.47MB
异物_2016-04-18_00-07-25_ACT_541#录波器.etr-15 2.83MB
雷击_雷击_1_0_12_新会站_20140509能新线_2014年05月09日18时04分37秒.etr-15 2.27MB
鸟害_2015年07月13日11时25分11秒.etr-15 1.49MB
外力破坏_2016年07月20日09时08分05秒.etr-15 540KB
异物_异物_2_0_8_潮阳站侧继电保护动作情况_20141107汕阳线(11点10分)_2014-11-07@11-11-09.#482.etr-150 276KB
异物_异物_2_0_8_胪岗侧_20141027胪祯乙线_141027234314.etr-151 1.01MB
异物_异物_2_0_8_汕头站侧继电保护动作情况_20141107汕阳线(11点10分)_2014年11月07日11时10分08秒.etr-152 291KB
异物_异物_3_0_8_茅湖站侧_20140811惠茅乙线_2014年08月11日13时51分57秒.etr-153 500KB
异物_2016年04月17日00时08分25秒.etr-16 1.07MB
鸟害_2015年07月13日11时25分13秒.etr-16 975KB
外力破坏_2016年07月20日09时26分14秒.etr-16 879KB
雷击_雷击_1_0_16_乐园_20140510桂乐甲线_SSH158.etr-16 196KB
异物_2016-04-25@13-54-36.#400F63.etr-17 1.31MB
鸟害_2015年07月13日12时53分04秒.etr-17 975KB
外力破坏_2016年08月31日07时40分23秒.etr-17 528KB
外力破坏_2016年08月31日07时40分23秒.etr-18 20.32MB
异物_2016-04-25_13-54-36_act_220kV录波屏(A0307120254).etr-18 1.22MB
雷击_雷击_1_0_24_蝶岭站_20140509蝶坝线_2014年05月09日19时08分12秒.etr-18 1.17MB
鸟害_2015年08月06日11时42分13秒.etr-18 972KB
雷击_雷击_1_0_24_国安站侧_20140509国珠甲线_2014年05月09日11时32分26秒.etr-19 1.35MB
鸟害_220kV故障录波器I(ZH-3)cpu1@20150806-114213#245#0#0.etr-19 972KB
异物_2016-04-27@14-21-46.#9C3482.etr-19 636KB
外力破坏_160912145036.etr-19 556KB
异物_2016年07月08日13时17分50秒.etr-2 964KB
风偏_2016-10-21@10-52-40.#15.etr-2 369KB
对树木放电_对树木放电_1_0_16_海港甲线(大港)_20140606海港甲线_SSH519.etr-2 229KB
外力破坏_2016年01月08日02时21分02秒_SSH991.etr-2 194KB
异物_2016年04月27日14时21分44秒.etr-20 801KB
鸟害_220kV线路故障录波器(ZH-5)2015-08-06@11-42-14.#C321.etr-20 402KB
外力破坏_2015年09月13日14时50分34秒.etr-20 222KB
雷击_雷击_1_0_24_联禾站_20140509源联乙线_SSH889.etr-20 130KB
鸟害_广东茂名曙光变220KV线路_2015年08月17日10时38分54秒307毫秒_comtrade.etr-21 520KB
雷击_雷击_1_0_24_群星站_20140511群北乙线_2014年05月11日12时41分57秒.etr-21 314KB
外力破坏_SSH513.etr-21 256KB
异物_W0427105222.etr-21 313B
外力破坏_2016年09月13日10时26分50秒.etr-22 1.82MB
鸟害_220k线路录波器(YS-900A)2015-08-17-10_38_54-000-00182-00339.etr-22 1.65MB
共 325 条
- 1
- 2
- 3
- 4
资源评论
我悟了-
- 粉丝: 2177
- 资源: 133
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功