Support Vector Machine (SVM) is a supervised learning method where training documents are represented as points in n-dimensional space. The SVM constructs a number of hyperplanes that subdivide the space. Optional parameters: - type = CLASSIFICA
(self, *args, **kwargs)
| 2141 | class SVM(Classifier): |
| 2142 | |
| 2143 | def __init__(self, *args, **kwargs): |
| 2144 | """ Support Vector Machine (SVM) is a supervised learning method |
| 2145 | where training documents are represented as points in n-dimensional space. |
| 2146 | The SVM constructs a number of hyperplanes that subdivide the space. |
| 2147 | Optional parameters: |
| 2148 | - type = CLASSIFICATION, |
| 2149 | - kernel = LINEAR, |
| 2150 | - degree = 3, |
| 2151 | - gamma = 1/len(SVM.features), |
| 2152 | - coeff0 = 0, |
| 2153 | - cost = 1, |
| 2154 | - epsilon = 0.01, |
| 2155 | - cache = 100, |
| 2156 | - shrinking = True |
| 2157 | """ |
| 2158 | import svm |
| 2159 | self._svm = svm |
| 2160 | # Cached LIBSVM or LIBLINEAR model: |
| 2161 | self._model = None |
| 2162 | # SVM.extensions is a tuple of extension modules that can be used. |
| 2163 | # By default, LIBLINEAR will be used for linear SVC (it is faster). |
| 2164 | # If you do not want to use LIBLINEAR, use SVM(extension=LIBSVM). |
| 2165 | self._extensions = \ |
| 2166 | kwargs.get("extensions", |
| 2167 | kwargs.get("extension", (LIBSVM, LIBLINEAR))) |
| 2168 | # Optional parameters are read-only: |
| 2169 | if len(args) > 0: |
| 2170 | kwargs.setdefault( "type", args[0]) |
| 2171 | if len(args) > 1: |
| 2172 | kwargs.setdefault("kernel", args[1]) |
| 2173 | if len(args) > 2: |
| 2174 | kwargs.setdefault("degree", args[2]) |
| 2175 | for k1, k2, v in ( |
| 2176 | ( "type", "s", CLASSIFICATION), |
| 2177 | ( "kernel", "t", LINEAR), |
| 2178 | ( "degree", "d", 3), # For POLYNOMIAL. |
| 2179 | ( "gamma", "g", 0), # For POLYNOMIAL + RADIAL. |
| 2180 | ( "coeff0", "r", 0), # For POLYNOMIAL. |
| 2181 | ( "cost", "c", 1), # Can be optimized with gridsearch(). |
| 2182 | ( "epsilon", "p", 0.1), |
| 2183 | ( "nu", "n", 0.5), |
| 2184 | ( "cache", "m", 100), # MB |
| 2185 | ( "shrinking", "h", True)): |
| 2186 | v = kwargs.get(k2, kwargs.get(k1, v)) |
| 2187 | setattr(self, "_"+k1, v) |
| 2188 | Classifier.__init__(self, train=kwargs.get("train", []), baseline=FREQUENCY) |
| 2189 | |
| 2190 | @property |
| 2191 | def extension(self): |
nothing calls this directly
no test coverage detected