'GridSearchCV' object has no attribute 'cv_results_' when fitting ExponentiatedGradient from fairlearn - gridsearchcv

The GridSearchCV is passed to ExponentiatedGradient. But after fitting the ExponentiatedGradient, cv_results_ are not returned.
gs = GridSearchCV(
estimator=model,
param_grid=param,
cv=RepeatedKFold(n_splits=5, n_repeats=2),
scoring=scoring,
return_train_score=True,
refit='roc_auc_curve',
n_jobs=-1)
mitigator = ExponentiatedGradient(gs, constraints=EqualizedOdds())
mitigator.fit(train_X, y_train, sensitive_features=x_train[set_sa])
print(mitigator.estimator)
GridSearchCV(cv=RepeatedKFold(n_repeats=2, n_splits=5, random_state=None),
estimator=RandomForestClassifier(), n_jobs=-1,
param_grid={'max_depth': [4, 7, 10],
'n_estimators': [100, 250, 500]},
refit='roc_auc_curve', return_train_score=True,
scoring={'acc': 'accuracy', 'bal_acc': 'balanced_accuracy',
'f1': 'f1', 'f1_weighted': 'f1_weighted',
'gmean': make_scorer(geometric_mean_score),
'roc_auc_curve': make_scorer(roc_auc_score, needs_proba=True, max_fpr=0.001)})
print(mitigator.estimator.cv_results_)
AttributeError: 'GridSearchCV' object has no attribute 'cv_results_'

Related

convert array of object to array of integer in ruby

So I want to convert in ruby
[{:user_id => 4}, {:user_id => 22}, {:user_id=>51}, {:user_id=>52}]
to
[4, 22, 51, 52]
Is there way of convert this?
As simple as possible: array.flat_map(&:values)
Very simple, let's use map to transform each item in something else
array.map { |item| item[:user_id] }
=> [4, 22, 51, 52]

Group array items using underscore

I have six items in my array: [1, 2, 3, 4, 5, 6]. I would like to group array items per 3 items like that: [[1, 2, 3], [4, 5, 6]]. Is it possible with underscore?
You can use array#reduce to group your array element.
const arr = [1, 2, 3, 4, 5, 6],
group = 3,
result = arr.reduce((r,v,i) => {
let index = Math.floor(i/group);
(r[index] = r[index] || [])[i%group] = v;
return r;
},[]);
console.log(result);

How to duplicate array within same array x times?

So, I have made function that return publicKey and I need to duplicate it x times for later use.
For example: publicKey: [76, 152, 93, 102, 145, 181] and I need to duplicate it 3 times, so the end result should be [76, 152, 93, 102, 145, 181, 76, 152, 93, 102, 145, 181, 76, 152, 93, 102, 145, 181].
I have tried using var list3 = publicKey*x, but as you can imagine, it didn't work..
fun getPublicKey(privateKey: ArrayList<BigInteger>,
birthDay: BigInteger,
primNumb: BigInteger): ArrayList<BigInteger> {
val inversMod = birthDay.modInverse(primNumb)
//println(inversMod)
val publicKey: ArrayList<BigInteger> = ArrayList()
for (keyValue in privateKey){
val pagaiduValue = (keyValue * inversMod).mod(primNumb)
//println("($keyValue * $inversMod) mod $primNumb = $pagaiduValue")
publicKey.add(pagaiduValue)
}
return publicKey
}
Here's a short and simple solution:
inline fun <T> Iterable<T>.times(count: Int) = (1..count).flatMap { this }
Can be used like this:
val numbers = listOf(1, 2, 3)
val result = numbers.times(5)
println(result) // [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]
Perhaps the naming could use some work, times could also be assumed to have the effect of multiplying each element by a given number, repeat could be a better alternative. Also, you might wanna define it on Array<T> and the primitive array types (IntArray, etc) as well.

ReactJS: How to read and write to a file

I have a file config.js which contain various objects and arrays. It is a large file so i decided to keep it as a separate file. I want to read this array called Config.EmojiCategorySpritesheetDimens from my config.js file in a component file called TextDisplay.js. How could this be done using React or React-Redux. Please help
config.js
var Config = {};
Config.Emoji = {
"00a9": ["\u00A9", ["copyright"]],
"00ae": ["\u00AE", ["registered"]],
"203c": ["\u203C", ["bangbang"]],
"2049": ["\u2049", ["interrobang"]],
"2122": ["\u2122", ["tm"]],
...etc
}
Config.EmojiCategorySpritesheetDimens = [
[7, 27],
[4, 29],
[7, 33],
[3, 34],
[7, 34]
];
Using module.export, I succeed reading the table:
var Config = {};
Config.Emoji = {
"00a9": ["\u00A9", ["copyright"]],
"00ae": ["\u00AE", ["registered"]],
"203c": ["\u203C", ["bangbang"]],
"2049": ["\u2049", ["interrobang"]],
"2122": ["\u2122", ["tm"]]
}
Config.EmojiCategorySpritesheetDimens = [
[7, 27],
[4, 29],
[7, 33],
[3, 34],
[7, 34]
];
module.exports = Config;
result:
config.js is then available in all the component defined in TextDisplay.js

How to remove elements from array that match elements in another array

How to remove elements from array that match elements in another array?
Assume we have an array and we loop through it and find out which elements to remove:
var sourceItems = [ ... ]
var removedItems = [SKShapeNode]()
for item : SKShapeNode in sourceItems {
if item.position.y > self.size.height {
removedItems.append(item)
item.removeFromParent()
}
}
sourceItems -= removedItems // well that won't work.
You can use the filter function.
let a = [1, 2, 3]
let b = [2, 3, 4]
let result = a.filter { element in
return !b.contains(element)
}
result will be [1]
Or more succinctly...
let result = a.filter { !b.contains($0) }
Check out the Swift Standard Library Reference
Or you can use the Set type.
let c = Set<Int>([1, 2, 3])
let d = Set<Int>([2, 3, 4])
c.subtract(d)
Be mindful if using the Set option, that your results only be unique values and will not maintain the initial ordering, if that matters to you, whereas the Array filter option will maintain the initial array's order, at least what elements remain.
Swift 3
let c = Set<Int>([65, 1, 2, 3, 1, 3, 4, 3, 2, 55, 43])
let d = Set<Int>([2, 3, 4])
c.subtracting(d)
c = {65, 2, 55, 4, 43, 3, 1}
d = {2, 3, 4}
result = {65, 55, 43, 1}

Resources