given the following signal, produce a synthetic prediction signal with the given…
- User
given the following signal, produce a synthetic prediction signal with the given percentage of correct predictions.
observe that s has length 21, but your synthetic prediction will have a length of 20.
fill in the variable prediction, with a list with 20 zeros or ones, containing a prediction with acc correct predictions.
for instance, with the following signal
[100.37 102.92 102.69 104.57 105.06 97.9 103. 100.32 97.59 107.07 112.19 106.32 104.14 100.3 97.03 107.28 100.36 100.99 111.48 117.07 126.04]
the following predictions:
p = [1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0]
produce a trend prediction accuracy of 60% (acc=0.6)
HINT: Do it in Python
use the perfect prediction from the exercise above to start with. use np.random.permutation
for instance:
a list
a = np.r_[10,20,30,40,50,60,70,80,90]
3 positions randomly chosen
k = np.random.permutation(len(a)-1)[:3] print (k)
changing the value of the items on those positions
a[k] = a[k] + 1 a
[2 4 5] array([10, 20, 31, 40, 51, 61, 70, 80, 90])
your signal and target accuracy to achieve
YOUR SIGNAL [108.81 104.54 107.94 103.97 104.32 109.06 104.46 102.01 106.5 108.27 104.63 97.74 102.8 104.85 108.24 109.16 104.34 96.73 103.27 97.94 95.64] THE ACCURACY YOUR SYNTHETIC PREDICTIONS MUST ACHIEVE: 0.9
Please fill the following variable:
my_synthetic_prediction = []
- Assistant
Based on your signal, the perfect prediction would be:
codeperfect_prediction = [0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1]Now let's create a synthetic prediction with 90% (acc=0.9) accuracy.
pythonimport numpy as np perfect_prediction = [0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1] # Calculate the number of errors needed to achieve 90% accuracy errors = int(len(perfect_prediction) * 0.1) # Choose random positions for errors positions = np.random.permutation(len(perfect_prediction)-1)[:errors] # Create synthetic prediction by modifying the perfect_prediction at error positions my_synthetic_prediction = perfect_prediction.copy() for pos in positions: my_synthetic_prediction[pos] = 1 - my_synthetic_prediction[pos]Here's an example output for my_synthetic_prediction:
codemy_synthetic_prediction = [0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1]Keep in mind that the output may be different if you run the code again since random positions are chosen for errors.