Skip to content

Commit

Permalink
Merge pull request #5 from lennepkade/beta
Browse files Browse the repository at this point in the history
Merge from beta
  • Loading branch information
nkarasiak authored Jun 24, 2016
2 parents 32ac811 + 1f9dae2 commit 70d1fa3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
12 changes: 10 additions & 2 deletions dzetsaka.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ def loadMenu(self):
self.menu.filterMedian = QAction(QIcon(":/plugins/dzetsaka/img/filter.png"), "Median", self.iface.mainWindow())
QObject.connect(self.menu.filterMedian, SIGNAL("triggered()"), self.loadFilters)
filterMenu.addAction(self.menu.filterMedian)

## Separator
filterMenu.addSeparator()

self.menu.filterClass = QAction(QIcon(":/plugins/dzetsaka/img/historicalmap.png"), "Classification to Vector (single class)", self.iface.mainWindow())
QObject.connect(self.menu.filterClass, SIGNAL("triggered()"), self.loadHistoricalMap)
filterMenu.addAction(self.menu.filterClass)

## Separator
filterMenu.addSeparator()
Expand Down Expand Up @@ -774,9 +781,10 @@ def loadHistoricalMap(self):
"""!@brief Load and init historical map dock"""
self.historicalmap = historical_dock()

self.historicalmap.show()

if self.sender()==self.menu.filterClass:
self.historicalmap.tabWidget.setCurrentIndex(1)

self.historicalmap.show()

# save raster
self.historicalmap.outRasterButton.clicked.connect(self.select_output_file)
Expand Down
6 changes: 3 additions & 3 deletions metadata.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file contains metadata for your plugin. Since
# This file contains metadata for your plugin. Since
# version 2.0 of QGIS this is the proper way to supply
# information about a plugin. The old method of
# embedding metadata in __init__.py will
Expand All @@ -8,7 +8,7 @@

[general]
name=dzetsaka : Classification tool
qgisMinimumVersion=2.0
qgisMinimumVersion=2.0.1
description=Fast and Easy Classification plugin for Qgis
version=2.0
author=Nicolaï Van Lennepkade
Expand All @@ -23,7 +23,7 @@ repository=http://www.github.com/lennepkade/dzetsaka
# Recommended items:

# Uncomment the following line and add your changelog:
changelog= Now support Random Forest, SVM and KNN classifiers. Correct some bugs and add settings management.
changelog= Now support Random Forest, SVM and KNN classifiers (v2.0). Correct some bugs (split classification) and add classification to vector in filters menu.
# Tags are comma separated with spaces allowed
tags=classification,semi-automatic,gaussian,mixture,model,random forest,svm,knn,forest

Expand Down
20 changes: 14 additions & 6 deletions scripts/mainfunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe
learningProgress.addStep() # Add Step to ProgressBar

# Learning process take split of groundthruth pixels for training and the remaining for testing
"""


try:
if SPLIT < 1:
Expand All @@ -128,7 +128,7 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe
#Add Pb
except:
QgsMessageLog.logMessage("Problem while learning if SPLIT <1")
"""


x,y=X,Y

Expand All @@ -150,28 +150,36 @@ def __init__(self,inRaster,inVector,inField='Class',outModel=None,inSplit=1,inSe
from sklearn.ensemble import RandomForestClassifier
from sklearn.cross_validation import StratifiedKFold
from sklearn.grid_search import GridSearchCV
try:
try:

# AS Qgis in Windows doensn't manage multiprocessing, force to use 1 thread for not linux system
if os.name == 'posix':
n_jobs=-1
else:
n_jobs=1

#
if inClassifier == 'RF':
param_grid_rf = dict(n_estimators=3**sp.arange(1,5),max_features=sp.arange(1,4))
y.shape=(y.size,)
cv = StratifiedKFold(y, n_folds=3)
grid = GridSearchCV(RandomForestClassifier(), param_grid=param_grid_rf, cv=cv,n_jobs=1)
grid = GridSearchCV(RandomForestClassifier(), param_grid=param_grid_rf, cv=cv,n_jobs=n_jobs)
grid.fit(x, y)
model = grid.best_estimator_
model.fit(x,y)
elif inClassifier == 'SVM':
param_grid_svm = dict(gamma=2.0**sp.arange(-4,4), C=10.0**sp.arange(-2,5))
y.shape=(y.size,)
cv = StratifiedKFold(y, n_folds=5)
grid = GridSearchCV(SVC(), param_grid=param_grid_svm, cv=cv,n_jobs=1)
grid = GridSearchCV(SVC(), param_grid=param_grid_svm, cv=cv,n_jobs=n_jobs)
grid.fit(x, y)
model = grid.best_estimator_
model.fit(x,y)
elif inClassifier == 'KNN':
param_grid_knn = dict(n_neighbors = sp.arange(1,20,4))
y.shape=(y.size,)
cv = StratifiedKFold(y, n_folds=3)
grid = GridSearchCV(neighbors.KNeighborsClassifier(), param_grid=param_grid_knn, cv=cv,n_jobs=1)
grid = GridSearchCV(neighbors.KNeighborsClassifier(), param_grid=param_grid_knn, cv=cv,n_jobs=n_jobs)
grid.fit(x, y)
model = grid.best_estimator_
model.fit(x,y)
Expand Down

0 comments on commit 70d1fa3

Please sign in to comment.