MilesCranmer commited on
Commit
cdd291e
1 Parent(s): 79ff57c

Correct examples in docs

Browse files
Files changed (1) hide show
  1. docs/examples.md +9 -20
docs/examples.md CHANGED
@@ -28,8 +28,9 @@ Here, we define a custom operator and use it to find an expression:
28
  X = 2 * np.random.randn(100, 5)
29
  y = 1 / X[:, 0]
30
  model = PySRRegressor(
31
- binary_operators=["plus", "mult"],
32
  unary_operators=["inv(x) = 1/x"],
 
33
  )
34
  model.fit(X, y)
35
  print(model)
@@ -44,31 +45,15 @@ each requiring a different feature.
44
  X = 2 * np.random.randn(100, 5)
45
  y = 1 / X[:, [0, 1, 2]]
46
  model = PySRRegressor(
47
- binary_operators=["plus", "mult"],
48
  unary_operators=["inv(x) = 1/x"],
 
49
  )
50
  model.fit(X, y)
51
  ```
52
 
53
  ## 4. Plotting an expression
54
 
55
- Here, let's use the same equations, but get a format we can actually
56
- use and test. We can add this option after a search via the `set_params`
57
- function:
58
-
59
- ```python
60
- model.set_params(extra_sympy_mappings={"inv": lambda x: 1/x})
61
- model.sympy()
62
- ```
63
-
64
- If you look at the lists of expressions before and after, you will
65
- see that the sympy format now has replaced `inv` with `1/`.
66
- We can again look at the equation chosen:
67
-
68
- ```python
69
- print(model)
70
- ```
71
-
72
  For now, let's consider the expressions for output 0.
73
  We can see the LaTeX version of this with:
74
 
@@ -82,7 +67,7 @@ Let's plot the prediction against the truth:
82
 
83
  ```python
84
  from matplotlib import pyplot as plt
85
- plt.scatter(y[:, 0], model(X)[:, 0])
86
  plt.xlabel('Truth')
87
  plt.ylabel('Prediction')
88
  plt.show()
@@ -92,6 +77,10 @@ Which gives us:
92
 
93
  ![Truth vs Prediction](images/example_plot.png)
94
 
 
 
 
 
95
  ## 5. Feature selection
96
 
97
  PySR and evolution-based symbolic regression in general performs
 
28
  X = 2 * np.random.randn(100, 5)
29
  y = 1 / X[:, 0]
30
  model = PySRRegressor(
31
+ binary_operators=["+", "*"],
32
  unary_operators=["inv(x) = 1/x"],
33
+ extra_sympy_mappings={"inv": lambda x: 1/x},
34
  )
35
  model.fit(X, y)
36
  print(model)
 
45
  X = 2 * np.random.randn(100, 5)
46
  y = 1 / X[:, [0, 1, 2]]
47
  model = PySRRegressor(
48
+ binary_operators=["+", "*"],
49
  unary_operators=["inv(x) = 1/x"],
50
+ extra_sympy_mappings={"inv": lambda x: 1/x},
51
  )
52
  model.fit(X, y)
53
  ```
54
 
55
  ## 4. Plotting an expression
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  For now, let's consider the expressions for output 0.
58
  We can see the LaTeX version of this with:
59
 
 
67
 
68
  ```python
69
  from matplotlib import pyplot as plt
70
+ plt.scatter(y[:, 0], model.predict(X)[:, 0])
71
  plt.xlabel('Truth')
72
  plt.ylabel('Prediction')
73
  plt.show()
 
77
 
78
  ![Truth vs Prediction](images/example_plot.png)
79
 
80
+ We may also plot the output of a particular expression
81
+ by passing the index of the expression to `predict` (or
82
+ `sympy` or `latex` as well)
83
+
84
  ## 5. Feature selection
85
 
86
  PySR and evolution-based symbolic regression in general performs