{"record":{"id":"f4b47997cf8bd25b","repo":"TheAlgorithms/Python","slug":"unknown-kernel-kernel","errorCode":null,"errorMessage":"Unknown kernel: {kernel}","messagePattern":"Unknown kernel: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"machine_learning/support_vector_machines.py","lineNumber":78,"sourceCode":"    ) -> None:\n        self.regularization = regularization\n        self.gamma = gamma\n        if kernel == \"linear\":\n            self.kernel = self.__linear\n        elif kernel == \"rbf\":\n            if self.gamma == 0:\n                raise ValueError(\"rbf kernel requires gamma\")\n            if not isinstance(self.gamma, (float, int)):\n                raise ValueError(\"gamma must be float or int\")\n            if not self.gamma > 0:\n                raise ValueError(\"gamma must be > 0\")\n            self.kernel = self.__rbf\n            # in the future, there could be a default value like in sklearn\n            # sklear: def_gamma = 1/(n_features * X.var()) (wiki)\n            # previously it was 1/(n_features)\n        else:\n            msg = f\"Unknown kernel: {kernel}\"\n            raise ValueError(msg)\n\n    # kernels\n    def __linear(self, vector1: ndarray, vector2: ndarray) -> float:\n        \"\"\"Linear kernel (as if no kernel used at all)\"\"\"\n        return np.dot(vector1, vector2)\n\n    def __rbf(self, vector1: ndarray, vector2: ndarray) -> float:\n        \"\"\"\n        RBF: Radial Basis Function Kernel\n\n        Note: for more information see:\n            https://en.wikipedia.org/wiki/Radial_basis_function_kernel\n\n        Args:\n            vector1 (ndarray): first vector\n            vector2 (ndarray): second vector)\n\n        Returns:","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/machine_learning/support_vector_machines.py#L60-L96","documentation":"Raised by the SupportVectorMachine constructor when the kernel string is anything other than 'linear' or 'rbf'. The constructor maps the string to an internal kernel method and has no fallback, so an unrecognized name fails fast with a message echoing the bad value.","triggerScenarios":"Calling SupportVectorMachine(kernel='poly'), kernel='sigmoid', or any typo like 'RBF' or 'Linear' (matching is case-sensitive).","commonSituations":"Copying kernel names valid in sklearn (poly, sigmoid, precomputed) into this class, case mismatches, or whitespace in config strings (' rbf').","solutions":["Use exactly 'linear' or 'rbf'.","If you imported the name from elsewhere, strip and lower-case it: kernel=kernel.strip().lower().","For kernels this class lacks (poly, sigmoid), implement them externally or use a library that supports them."],"exampleFix":"# before\nsvm = SupportVectorMachine(kernel='poly')\n\n# after\nsvm = SupportVectorMachine(kernel='rbf')  # or 'linear'; only these exist","handlingStrategy":"validation","validationCode":"kernel = kernel.strip().lower()\nif kernel not in ('linear', 'rbf'):\n    raise ValueError(f\"unsupported kernel {kernel!r}; use 'linear' or 'rbf'\")\nsvm = SupportVectorMachine(kernel=kernel)","typeGuard":"def is_supported_kernel(name: str) -> bool:\n    return isinstance(name, str) and name.strip().lower() in ('linear', 'rbf')","tryCatchPattern":null,"preventionTips":["Keep the supported-kernel list next to your config schema.","Normalize case and whitespace of config strings before use."],"tags":["machine-learning","svm","configuration","enum-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}