Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
svm script
#1
Dear All the following svm script, gives the error (raise IOError("Cannot understand given URI: %s." % uri_r),

Would you please to show me where is my mistake,

# import all the required modules

from skimage.io import imread
from pathlib import Path
from sklearn.model_selection import train_test_split, GridSearchCV
import numpy as np 
import numpy
from sklearn import svm, metrics


def ReadImage(filepath, dimension=(500, 581)):
    
    """
    Load and read stacked-image file
        
    Parameters
    ----------
    container_path : string or unicode
    Path to the main folder holding one category
    dimension : tuple
    size to which image are adjusted to
    
    Returns
    -------
    np.arry of stacked image
    """
    img = imread(filepath)
    
    return np.array(img)

def SplitData(file):
    img = imread(file)
    imge = []
    target = []
    for r, c in img:
        imge.append(X_train)
        target.append(y_train)
        X_train, X_test, y_train, y_test = train_test_split(imge,
                                                            target,
                                                            test_size=.25,
                                                            random_state=123)
    return SplitData
    
    
    

def ReshapeImage(X_train, y_train):
    nsamples, nx, ny = X_train.shape
    dx_train_dataset = X_train.reshape((nsamples,nx*ny))
    
    nsamples, nx, ny = y_train.shape
    dy_train_dataset = y_train.reshape((nsamples,nx*ny))
    
    return ReshapeImage

def Classifier(clf, param_grid):
    svc = svm.SVC()
    param_grid = [
  {'C': [1, 10, 100, 1000], 'kernel': ['linear']},
  {'C': [1, 10, 100, 1000], 'gamma': [0.001, 0.0001], 'kernel': ['rbf']},
 ]
    clf = GridSearchCV(svc, param_grid)
    clf.fit(dx_train_dataset, dy_train_dataset)
    y_pred = Classifier.predict(X_test)
    print ("Accuracy: %s" % Classifier.score(X_test, y_test))
    print("Classification report for - \n{}:\n{}\n".format(
    clf, metrics.classification_report(y_test, y_pred)))
    return Classifier


stacked_img = ReadImage('D:\MyProject\preprocessing\stacked_data\data_stacked.tif'
                        ,dimension=(500, 581))

spd = SplitData(stacked_img)
Reply


Messages In This Thread
svm script - by falahfakhri - Sep-02-2020, 11:29 AM
RE: svm script - by Larz60+ - Sep-02-2020, 02:17 PM
RE: svm script - by falahfakhri - Sep-03-2020, 06:08 AM
RE: svm script - by bowlofred - Sep-03-2020, 06:17 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020