昨天好不容易心氣爆發,肝了一下子的畢業設計,也算是初步走上了正軌,非常期待後面完成以後我本身回首會是怎樣通常場景了!不過昨天那個對半劃分數據集,一半做爲訓練集,一半做爲驗證集的劃分方式效果實在是使人不敢恭維。。。我是死了心這麼分了。到時候畢設答辯的時候拿這個去說簡直就是丟死人了。java
我此次採用的是之前的那一撥鋼板的數據集,清洗數據後剩下六個屬性,分類也分爲六類。這就構成了這個1940條記錄的數據集。可是由於數據的分類過於集中。非常讓人煩惱!mysql
諸君請看,前面的這些異常分類都是0,也就是對應的故障列表的第一項:sql
String[] Fault = new String[]{"Pastry","Z_Scratch","K_Scatch","Stains","Dirtiness","Bumps","Other_Faults"};
複製代碼
mysql> select min(id) from steelplate where Fault=1;
+---------+
| min(id) |
+---------+
| 158 |
+---------+
1 row in set (0.01 sec)
複製代碼
分類爲1 的最小的記錄編號都已經到了158了。因此我選擇交叉獲取數據的方式分配訓練集和數據集。即第一條到訓練集,第二條到驗證集。這樣下來尚且算是分配均勻了。bash
不過各位看看最終的實驗效果就知道。。我這個分配均勻到底有多坑了!函數
準確率0.51。。。。堪堪過半!!簡直無敵自容了好嗎?!!!!因此今天我準備修改訓練集和驗證集 的比例,調成4:1左右的話會不會好一點呢?確定會的好嗎?這時候訓練集有1552,測試集388。並且繼續採用交叉辦法,確定能有較好的效果了!測試
//讀取測試集和驗證集的方法
public Object[][] readTrainData() {
int columnCount=0;
try {
mysql.Connect();
Statement statement=mysql.getStatement();
String GETCOLUMN="select max(id) from steelplate";
String getDataQuery="";
Object[][] DataTrain;
ResultSet answer = statement.executeQuery(GETCOLUMN);
if(answer.next())
columnCount = answer.getInt(1);
DataTrain = new Object[columnCount/2][7];
for (int i = 0;i<columnCount/2;++i) {
getDataQuery = getSelectQuery(Name,"steelplate",i*2);
ResultSet select_ok;
select_ok = statement.executeQuery(getDataQuery);
select_ok.next();
for (int j = 0; j<7;++j){
DataTrain[i][j]=select_ok.getObject((String) Name[j]);
}
}
statement.close();
mysql.Dis_Connect();
return DataTrain;
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return new Object[1][1];
}
public Object[][] readTestData() {
int columnCount=0;
try {
mysql.Connect();
Statement statement=mysql.getStatement();
String GETCOLUMN="select max(id) from steelplate";
Object[][] DataTest;
ResultSet answer = statement.executeQuery(GETCOLUMN);
if(answer.next())
columnCount = answer.getInt(1);
DataTest = new Object[columnCount/2][7];
for (int i = 0 ;i<columnCount/2-1;++i) {
String getDataQuery = getSelectQuery(Name,"steelplate",i*2+1);
ResultSet select_ok;
select_ok = statement.executeQuery(getDataQuery);
select_ok.next();
for (int j = 0; j<7;++j){
DataTest[i][j]=select_ok.getObject((String) Name[j]);
}
}
statement.close();
mysql.Dis_Connect();
return DataTest;
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return new Object[1][1];
}
複製代碼
下面是讀取驗證集而且計算正確率的函數spa
else if(command.toLowerCase().equals("autotest")){
if (TData.isEmpty()){
jl12.setText(Space+"Please Open the Test File to load the Data!");
return;
}
else {
for (int i=0;i<TData.size();++i) {
Object[] test = TData.get(i).split(" ");
String res="";
res=TestData.TestData(tree, Test_Names,test,res);
if (res.contains(":")){
String Fault = res.substring(res.indexOf(":")+1);
Fault = Fault.trim();
String Fa = FaultMap.get(Fault);
if(Fa.equals((String) test[test.length-1])){
RightCount++;
}
else {
FaultCount++;
}
}
else {
FaultCount++;
}
}
System.out.println(RightCount+" "+FaultCount);
jl12.setText(Space+"準確率: "+((float)RightCount/(float)(RightCount+FaultCount)));
RightCount = 0;
FaultCount = 0;
}
}
複製代碼
另外還有一個故障編號Map設計
public Map<String,String> FaultMap = new HashMap<String,String>();
FaultMap.put("Pastry","0");
FaultMap.put("Z_Scratch","1");
FaultMap.put("K_Scatch","2");
FaultMap.put("Stains","3");
FaultMap.put("Dirtiness","4");
FaultMap.put("Bumps","5");
FaultMap.put("Other_Faults","6");
複製代碼
溜了溜了。。。我室友借我車去吃飯,結果半路上跟外賣小哥來了段相愛相殺,求問這種時候我室友還墊付了200+的醫藥費,萬一外賣小哥糾纏報警的話會吃虧不?外賣小哥的車技一貫是。。。生死時速的!code