fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from sklearn import linear_model, datasets
  4.  
  5. # import some data to play with
  6. iris = datasets.load_iris()
  7. X = iris.data[:, :2] # we only take the first two features.
  8. Y = iris.target
  9.  
  10. h = .02 # step size in the mesh
  11.  
  12. logreg = linear_model.LogisticRegression(C=1e5)
  13.  
  14. # we create an instance of Neighbours Classifier and fit the data.
  15. logreg.fit(X, Y)
  16.  
  17. # Plot the decision boundary. For that, we will assign a color to each
  18. # point in the mesh [x_min, x_max]x[y_min, y_max].
  19. x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
  20. y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
  21. xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
  22. Z = logreg.predict(np.c_[xx.ravel(), yy.ravel()])
  23.  
  24. # Put the result into a color plot
  25. Z = Z.reshape(xx.shape)
  26. plt.figure(1, figsize=(4, 3))
  27. plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)
  28.  
  29. # Plot also the training points
  30. plt.scatter(X[:, 0], X[:, 1], c=Y, edgecolors='k', cmap=plt.cm.Paired)
  31. plt.xlabel('Sepal length')
  32. plt.ylabel('Sepal width')
  33.  
  34. plt.xlim(xx.min(), xx.max())
  35. plt.ylim(yy.min(), yy.max())
  36. plt.xticks(())
  37. plt.yticks(())
  38.  
  39. plt.show()
  40.  
  41.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: '.' expected
import numpy as np
            ^
Main.java:1: error: ';' expected
import numpy as np
               ^
Main.java:2: error: ';' expected
import matplotlib.pyplot as plt
                        ^
Main.java:3: error: '.' expected
from sklearn import linear_model, datasets
                                ^
Main.java:3: error: ';' expected
from sklearn import linear_model, datasets
                                 ^
Main.java:5: error: illegal character: '#'
# import some data to play with
^
Main.java:5: error: class, interface, or enum expected
# import some data to play with
         ^
Main.java:7: error: illegal character: '#'
X = iris.data[:, :2]  # we only take the first two features.
                      ^
Main.java:10: error: illegal character: '#'
h = .02  # step size in the mesh
         ^
Main.java:14: error: illegal character: '#'
# we create an instance of Neighbours Classifier and fit the data.
^
Main.java:17: error: illegal character: '#'
# Plot the decision boundary. For that, we will assign a color to each
^
Main.java:18: error: illegal character: '#'
# point in the mesh [x_min, x_max]x[y_min, y_max].
^
Main.java:24: error: illegal character: '#'
# Put the result into a color plot
^
Main.java:29: error: illegal character: '#'
# Plot also the training points
^
Main.java:31: error: unclosed character literal
plt.xlabel('Sepal length')
           ^
Main.java:31: error: unclosed character literal
plt.xlabel('Sepal length')
                        ^
Main.java:32: error: unclosed character literal
plt.ylabel('Sepal width')
           ^
Main.java:32: error: unclosed character literal
plt.ylabel('Sepal width')
                       ^
18 errors
stdout
Standard output is empty