In this project, I work on classifying news articles as either fake or true using logistic regression. I use small datasets from GitHub, clean and prepare the text, convert it to TF-IDF format, and train the model using tidymodels. I also tune the penalty parameter using cross-validation and evaluate the model using accuracy, AUC, confusion matrix, and ROC curve. Finally, I show the most informative words that help the model decide between fake and true news. This is a full machine learning pipeline, from loading the data to interpreting the results.
We load all required libraries for modeling, text processing, and evaluation.
library(tidymodels)
## ── Attaching packages ────────────────────────────────────── tidymodels 1.2.0 ──
## ✔ broom 1.0.7 ✔ recipes 1.3.0
## ✔ dials 1.3.0 ✔ rsample 1.2.1
## ✔ dplyr 1.1.4 ✔ tibble 3.2.1
## ✔ ggplot2 3.5.1 ✔ tidyr 1.3.1
## ✔ infer 1.0.7 ✔ tune 1.2.1
## ✔ modeldata 1.4.0 ✔ workflows 1.1.4
## ✔ parsnip 1.2.1 ✔ workflowsets 1.1.0
## ✔ purrr 1.0.2 ✔ yardstick 1.3.2
## Warning: package 'scales' was built under R version 4.4.3
## Warning: package 'recipes' was built under R version 4.4.3
## ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
## ✖ purrr::discard() masks scales::discard()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ recipes::step() masks stats::step()
## • Learn how to get started at https://www.tidymodels.org/start/
library(textrecipes)
## Warning: package 'textrecipes' was built under R version 4.4.3
library(tidytext)
## Warning: package 'tidytext' was built under R version 4.4.3
library(yardstick)
library(stringr)
##
## Attaching package: 'stringr'
## The following object is masked from 'package:recipes':
##
## fixed
We read fake and true news CSV files from GitHub.
url_fake_small <- "https://raw.githubusercontent.com/farhodibr/CUNY-SPS-MSDS/refs/heads/main/DATA607/PROJECT4/Fake_small.csv"
url_true_small <- "https://raw.githubusercontent.com/farhodibr/CUNY-SPS-MSDS/refs/heads/main/DATA607/PROJECT4/True_small.csv"
# Read CSVs into data frames
df_fake <- as.data.frame(read.csv(url_fake_small))
df_true <- as.data.frame(read.csv(url_true_small))
View the first row of each dataset to understand the structure.
df_fake |> head(1)
## title
## 1 HOW GORSUCH Will Have Immediate Effect On Historic 2nd Amendment Decision And These Significant Controversial Cases
## text
## 1 Neil M. Gorsuch joins the Supreme Court just in time to cast potentially significant votes in cases that pit religious liberty against gay rights, test limits on funding for church schools and challenge California s restrictions on carrying a concealed gun in public.Such issues arise either in appeals filed by conservative groups that have been pending before the justices for weeks or in cases to be heard later this month.Gorsuch s votes in those matters may give an early sign of whether the court s conservatives with their 5-4 majority restored by his confirmation will pursue an activist agenda.The cases include a Colorado baker s claim that he deserves a faith-based exemption from the state s anti-discrimination law after he refused to design a wedding cake for a gay couple. The justices have been considering his appeal behind closed doors since December, but have taken no action. LA TimesA Second Amendment controversy arising from California, would be the biggest gun-rights decision in several years, should the justices agree to hear it.In D.C. v. Heller and McDonald v. Chicago, the Court ruled that the Constitution protects the right to keep functional firearms in the home for self-defense, and that state and local governments cannot infringe upon said right. The challenge now pending before the Court, Peruta v. California, involves the right to carry a firearm outside the home for self-defense.The 9th U.S. Circuit Court of Appeals issued a ruling in 2016 affording county governments in California significant leeway in the issuance of concealed carry permits. Some permit regimes in the state are fairly accommodating of applicants, while others make it functionally impossible to obtain a concealed carry license. A group of Second Amendment applicants challenged the 9th Circuit s decision.Should the justices take the case and side with the activists, they could announce a constitutionally-protected right to bear firearms outside the home for the first time in American history.Via: Daily Caller
## subject date
## 1 left-news Apr 9, 2017
df_true |> head(1)
## title
## 1 Bid to 'fix' Iran nuclear deal faces uphill climb in U.S. Congress
## text
## 1 WASHINGTON (Reuters) - President Donald Trump s call for Congress to toughen the Iran nuclear deal faced opposition on Friday from among the ranks of his fellow Republicans as well as from Democrats, narrowing the chances any legislation could pass. As Trump announced that he had chosen not to certify Tehran is complying with the deal but would not immediately withdraw from it, Republican Senators Bob Corker and Tom Cotton offered an outline of legislation they said would address flaws in the accord. If passed, the measure would set stricter restrictions on Iran and immediately revive U.S. sanctions imposed over Iran s nuclear program if Tehran is deemed able to produce a nuclear weapon within a year. We have provided a route to overcome deficiencies (in the agreement) and to keep the administration in the deal, and actually make it the kind of deal that it should have been in the first place, Corker, chairman of the Senate Foreign Relations Committee, said on a call with journalists. Republicans control Congress, but their four-seat edge in the Senate means any measure would need Democratic support to pass, even if every member of Trump s party supports it. That is not a given. Republican Senator Marco Rubio said he had serious doubts about the Corker-Cotton plan. He said he would reserve judgment until the final measure, but preferred that Trump abandon the deal. Ultimately, leaving the nuclear deal, reimposing suspended sanctions, and having the president impose additional sanctions would serve our national interest better than a decertified deal that leaves sanctions suspended or a new law that leaves major flaws in that agreement in place, Rubio said in a statement. Most Democrats were strongly opposed. Senator Ben Cardin, ranking Democrat on the Foreign Relations panel, said he would only support a measure backed by European allies who had signed the nuclear pact, formally known as the JCPOA. Anything we do must be consistent with the JCPOA, cannot lead us on a path to violate the JCPOA and must have the support of our European allies, he told Reuters in a telephone interview. Cardin said he wanted a full-Senate briefing on the plan from administration officials, and then committee hearings. Corker acknowledged the tough fight ahead, but said he hoped to win over Democrats. He pledged to seek the support of European allies Britain, France and Germany, who had signed the agreement and urged Trump not to decertify.
## subject date
## 1 worldnews October 13, 2017
We add labels and join title + text columns. Missing values are handled.
df_fake <- df_fake |> mutate(label = factor("fake"))
df_true <- df_true |> mutate(label = factor("true"))
# Combine and clean
df_combined <- bind_rows(df_fake, df_true) |>
mutate(
title = ifelse(is.na(title), "", title),
text = ifelse(is.na(text), "", text),
full_text = paste(title, text, sep = " ")
) |>
select(full_text, label) |>
mutate(doc_id = row_number()) |>
select(doc_id, full_text, label)
Shuffle rows and preview 10 examples.
set.seed(123)
df_combined <- df_combined |> slice_sample(prop = 1)
df_combined |> head(10)
## doc_id
## 1 2463
## 2 2511
## 3 2227
## 4 526
## 5 195
## 6 2986
## 7 1842
## 8 1142
## 9 3371
## 10 1253
## full_text
## 1 'Rage against the machine': U.S. voters reject a 'rigged' system (This November 9th story has been refiled to clarify that Keyes comment in 3rd paragraph from end was said in jest) By Andy Sullivan and Michelle Conlin WASHINGTON (Reuters) - In a bitterly divisive presidential election, at least one thing united U.S. voters: a feeling that the country’s economic and political systems were tilted against them. A Reuters/Ipsos Election Day poll of 45,000 voters found an electorate burning with resentment against Wall Street, politicians and the news media, increasingly alienated from a country that is changing in ways it doesn’t like. This sense of alienation transcended partisan boundaries, uniting supporters of Republican victor Donald Trump and his Democratic rival, Hillary Clinton. “This is rage against the machine,” said Carrie Sheridan, a former supporter of Democratic President Barack Obama, as fellow Trump supporters celebrated the real-estate mogul’s victory early Wednesday by pouring champagne on each other at his $200 million luxury hotel near the White House. Some 75 percent of poll respondents, Republicans and Democrats alike, agreed that the country needs a “strong leader” to take the country back from the rich and powerful. Seven out of ten agreed that the economy is “rigged” to benefit wealthy insiders. Most backed the notion that their leaders were out of touch: 77 percent of Trump supporters and 56 percent of Clinton supporters agreed that traditional politicians didn’t care about people like them. (Graphic of Reuters/Ipsos poll: tmsnrt.rs/2ffJJ9A) This sense of disconnection ran deepest among Trump supporters. Some 73 percent agreed with the idea that “more and more, I don’t identify with what America has become,” while 61 percent said they felt like strangers in their own country. Most Clinton supporters said they didn’t share those sentiments. Nine out of ten Trump supporters said mainstream media is more interested in making money than telling the truth. Trump, who travels in his own 757 jet, might seem like an unlikely candidate to benefit from this anti-elite sentiment. But by 8 p.m. Eastern time, lines had formed at the velvet ropes by 8 p.m. Eastern time outside Trump’s new hotel in between the White House and the U.S. Capitol, where a steak costs $60 and wine is sold by the spoonful. “These are shadow voters, voters who have never voted before,” said Preston Parry, 20, who was watching the results with a throng of friends, all of them wearing suits and Trump campaign trucker hats. Despite his gilded lifestyle, Trump capitalized on working-class fears of a rapidly changing country. Styling himself as a “blue-collar billionaire,” he promised to bring back manufacturing jobs back to forgotten factory towns and sharply curtail immigration. He drew overwhelming support from white working-class voters in Rust Belt states like Ohio and Pennsylvania, winning enough states to capture the White House even as he lost the popular vote. Trump’s scathing characterization of Clinton as a corrupt career politician also resonated in an year when many voters said they were primarily casting a vote against one of the candidates. Some 46 percent of Trump supporters said they backed him because they didn’t want Clinton to win, while 40 percent of Clinton supporters said they were motivated primarily to stop Trump from reaching the White House. Those who made up their minds in the last week of the campaign were more likely to cite opposition to one of the candidates as their main reason for voting. Politicians like Clinton are “taking away from what we were as a country and saying we should change because of the people coming in, the immigrants and refugees,” said John Scherer, a 57-year-old former maintenance worker in Portsmouth, Ohio. Scherer’s sentiments were widely shared by Trump supporters, as 72 percent agreed with the idea that immigrants threaten traditional American beliefs and customs. Three-quarters of Clinton backers, by contrast, said immigrants strengthened U.S. society. The Reuters/Ipsos Election Day poll was conducted online in English in all 50 states, including more than 45,000 people who already voted in the presidential election. Voter dissatisfaction isn’t exactly new. Surveys have consistently found since 2002 that most people believe the country is on the wrong track, a period that encompasses a Republican and Democratic president, two wars, a deep recession and a slow recovery. Trump supporters were more likely to share this frustration. Some 70 percent who backed the Republican real-estate mogul said they felt the country was on the wrong track, while only 23 percent of Clinton supporters agreed, according to the Reuters/Ipsos tracking poll. Those figures could quickly turn on their head as the reality of a Trump presidency sinks in. Across the country, Clinton supporters used unusually harsh language when describing the election result. In Washington, D.C., non-profit manager Trisha Postyuk said she saw her vote for Clinton as “a triumph over evil.” In St. Petersburg, Florida, cafe owner Amanda Keyes, 33, said racist and sexist attitudes are going to take many years to overcome. “Misogyny will continue to bubble through the country but I can only hope that the old people will die,” she said jokingly. At Trump’s hotel, a couple from Atlanta looked at a text message from a friend who had bet them $100 that Trump would lose. “Please don’t ever text me again,” the message said.
## 2 Former intelligence officials say Trump is being manipulated by Putin WASHINGTON (Reuters) - Two former top U.S. intelligence officials said on Sunday they fear President Donald Trump is being manipulated by Russian President Vladimir Putin, after Trump said he believed Putin was sincere in denying Russian meddling in the 2016 election. Former CIA Director John Brennan and ex-National Intelligence Director James Clapper both said Trump was mishandling Moscow ties even as a special counsel investigates possible collusion between Trump’s campaign team and Russia. “I think Mr. Trump is, for whatever reason, either intimidated by Mr. Putin, afraid of what he could do, or what might come out as a result of these investigations... It’s either naiveté, ignorance or fear in terms of what Mr. Trump is doing vis-à-vis the Russians,” Brennan said in an appearance with Clapper on CNN’s “State of the Union.” Clapper added that foreign leaders who roll out the red carpet for Trump are able to manipulate Trump. “I do think both the Chinese and the Russians think they can play him,” Clapper said. Their comments came after Trump told reporters over the weekend that he had spoken with Putin again over allegations of Russian meddling in the presidential election and that the Russian president again denied any involvement. “I really believe that, when he tells me that, he means it,” Trump told reporters. “I think he is very insulted by it, which is not a good thing for our country.” Treasury Secretary Steve Mnuchin said on the same show that the criticism leveled against Trump’s management of relations with Russia and China was “ridiculous.” “President Trump is not getting played by anybody,” Mnuchin said. Trump also took a swipe at Obama-era intelligence officials Brennan, Clapper and former FBI Director James Comey, calling them “political hacks” and questioning the findings of a U.S. intelligence report that concluded that Russians sought to tilt the election in Trump’s favor. Facing sharp criticism, Trump walked back from some of those comments on Sunday, saying he has faith in the intelligence leaders he has hired. Brennan on Sunday called Trump’s criticism of him a “badge of honor,” and Clapper suggested said Trump’s denial of Russian interference in the election “poses a peril to the country.” When asked, Brennan declined to say whether he knows of any intelligence to suggest that the Russians have compromising or damaging information on Trump. A dossier penned by a former British spy contains unverified claims that Russia does have embarrassing information on Trump.
## 3 China lodges stern protest with South Korea over THAAD deployment BEIJING (Reuters) - China said on Thursday it had lodged stern representations with South Korea for installing the four remaining launchers of the U.S. anti-missile Terminal High Altitude Area Defense (THAAD) system on a former golf course. Foreign Ministry spokesman Geng Shuang made the comment at a regular press briefing.
## 4 PRESIDENT TRUMP’S NEW CHIEF OF STAFF Wants His Boss To Stop Tweeting…But Only About One Thing Right before eighth grade, Trump s father sent him literally up the river to New York Military Academy in the Hudson Valley. Trump would spend the next five years there.Retired Col. Ted Dobias remembers the tall, lanky kid who showed up at his dormitory. I put [him] down at the end of the hall. He didn t know how to make a bed. He didn t know how to shine his shoes. He had a problem, you know, with being a cadet. You know, being a cadet, you gotta take care of yourself, Dobias said.And Trump the cadet didn t quite know how, at first. Dobias had a reputation for being one of the school s toughest instructors. He was a hardened World War II veteran who made it clear to Trump he didn t care who his daddy was. When he got out of line, he got the same treatment like everybody else. His name was Donald Trump, like Johnny Jones. It was all the same, Dobias said. Nobody was different. We treated everyone alike. Back in Trump s day, cadets would wake up near the crack of dawn, hurry into their uniforms and march in formation to breakfast. First-year cadets had to eat their meals squared-off lifting their forks in a right angle path into their mouths. And after breakfast, they d scurry back to clean their rooms for inspection. Dobias said it was a place where kids who didn t like following the rules learned to like it. It s a hell of a thing for a kid to go to a military school especially when you have to say, Yes sir, No sir, have to learn how to salute, how to do about-face, how to march, how to carry a gun, said Dobias.But instead of recoiling from the discipline, Trump thrived under it. In her book The Trumps: Three Generations of Builders and a Presidential Candidate, Gwenda Blair notes how Donald seemed to welcome being in a place with clear-cut parameters, a place where he could focus on figuring out how to come out on top and get what he wanted. Mike Kabealo, one of Trump s roommates at NYMA, said in the confines of the school s rigid rules, Trump wanted to be a standout. Cocksure, positive and anything-you-can-do-I-can-do-better kind of stuff you know, he was very competitive, Kabealo said.And friends say Trump channeled that competitiveness into everything at military school. When he was in charge of the rifle rack, he cleaned the rifles obsessively. He was meticulous about his uniform. When it was his turn to do inspections in the barracks, he whipped other cadets into shape. NPRGiven his success in the military academy, is it any surprise then, that President Trump would choose a former general to be his chief of staff?White House Chief of Staff John Kelly aims to stop President Trump from making policy announcements on Twitter, according to a report Friday night.While Kelly acknowledges he can t stop Trump from tweeting, the new chief of staff would like to know what the president plans to tweet before he does so. He would prefer big policy decisions not be announced on Twitter.The goal is pushing the tweets in the right direction, Politico reported, citing a White House official.Trump made waves on July 26 when he announced on Twitter that he would ban transgender people from the military:After consultation with my Generals and military experts, please be advised that the United States Government will not accept or allow Donald J. Trump (@realDonaldTrump) July 26, 2017 .Transgender individuals to serve in any capacity in the U.S. Military. Our military must be focused on decisive and overwhelming .. Donald J. Trump (@realDonaldTrump) July 26, 2017 .victory and cannot be burdened with the tremendous medical costs and disruption that transgender in the military would entail. Thank you Donald J. Trump (@realDonaldTrump) July 26, 2017The Defense Department has since said it won t execute a policy based on Trump s tweet until it would receives formal guidance, which the White House has not provided yet.Politico reported that White House and Defense Department lawyers had warned Trump against the transgender military ban, fearing the legal backlash that would follow. The lawyers only learned about Trump s decision when he tweeted it. Washington Examiner
## 5 WATCH: ‘The View’ Unanimously Rips Trump A New One For Groping Comments And It’s AMAZING The women of The View played the tape of Trump s grotesque remarks about groping women and they unanimously condemned him.The panelists of the show have a wide range of political views from liberal to conservative, but Trump s bragging about grabbing women by the p*ssy united them all against the Republican nominee and his campaign on Monday.Sunny Hostin kicked things off by explaining that she talked to a lot of men about Trump s remarks and even asked her husband and 14-year-old football player son if what Trump said is the kind of things men talk about in locker rooms. She said that none of the men she talked to said this is typical locker room talk and her son was horrified by what Trump said and confirmed that not even teenage boys talk that way in locker rooms. Men don t talk about sexually assaulting women, she said.Whoopi Goldberg chimed in by calling Trump s behavior piggish, which Joy Behar said is saying the least. Sara Haines said his remark turned my stomach and pointed out that men don t make a move on women by groping them. It s about power she continued.Hostin continued by pointing out that what Trump is bragging about is a crime punishable with time behind bars. And she would know since she is a former prosecutor who prosecuted sex crimes. Classic sexual assault, she said. People go to jail for that. He wants Hillary Clinton to go to jail? Maybe he needs to go to jail for sexually assaulting people. The audience cheered wildly for Hostin s statement, and then Jedediah Bila took her turn. He s talking about it like he was some kid in a locker room, Bila said. Yeah, maybe you ll find some stray person in a locker room that s talking like that, but they re not all running for president! They re not all trying to be the leader of the free world, Donald! Goldberg noted that four former presidents, two Democrats and two Republicans have all said that Trump is unfit for the office. Bila then sent a message to Republicans like Paul Ryan who still endorse Trump. If you don t withdraw your endorsement, you are putting your stamp of approval on this. Here s the video via Huffington Post.If this were any other presidential election in the past, Trump would have been removed or forced to drop out by now. But Republicans are so desperate for power that they don t care how despicable their nominee is. Not only should Trump lose by a landslide in November, but every Republican down the ticket should lose as well. This election needs to send a message to the GOP that they need to change.Featured image via screenshot
## 6 Germans see Trump as bigger problem than North Korea or Russia BERLIN (Reuters) - Germans see U.S. President Donald Trump as a bigger challenge for German foreign policy than authoritarian leaders in North Korea, Russia or Turkey, according to a survey by the Koerber Foundation. Topping the list of foreign policy concerns were refugees, with 26 percent of respondents worried about Germany s ability to cope with inflows of asylum seekers. Relations with Trump and the United States ranked second, with 19 percent describing them as a major challenge, followed by Turkey at 17 percent, North Korea at 10 percent and Russia at 8 percent. Since entering the White House in January, Trump has unsettled Germans by pulling out of the Paris climate accord, refusing to certify an international agreement on Iran s nuclear programme and criticizing Germany s trade surplus and its contributions to the NATO military alliance. Trump s actions prompted the usually cautious German Chancellor Angela Merkel to say earlier this year that Berlin may not be able to rely on the United States in the future. She also urged Europe to take its fate into its own hands. In the poll of 1,005 Germans of voting age, carried out in October, 56 percent of Germans described the relationship with the United States as bad or very bad. Despite Merkel s pledge, the survey showed deep scepticism in the population about Germany taking a more active role in international crises, with 52 percent of respondents saying the country should continue its post-war policy of restraint. That may reflect the fact that neither Merkel nor her main challengers in the recent election campaign talked much about how Germany should respond to the challenges posed by Trump s disruptive presidency and Britain s looming departure from the European Union. Last week, Norbert Roettgen, a member of Merkel s conservative party and head of the foreign affairs committee in the Bundestag, decried a deplorable lack of leadership in educating Germans about the need to invest more in their own defense and security.
## 7 GRAMMYS Nominate All-Black Artists…SNUB Country Music, White Musicians Over “White Supremacy” Concerns…#BoycottGrammys On Tuesday, the Grammys announced their nominations for the 2018 awards shows, and there are some notable additions and snubs that make it look like the Recording Academy is getting into the business of identity politics.For the first time in 14 years, no country music acts were nominated for the top awards: record of the year, song of the year, and album of the year. Instead, the Grammys took a sharp turn towards honoring hip-hop, R&B, and funk for the top awards.According to Buzzfeed: The night s biggest category, Album of the Year, not only has majority black nominees, but also has no white male nominees for the first time in 19 years.This is also the first year the Record of the Year category is only people of color (with the exception of Justin Bieber, who is featured on Luis Fonsi & Daddy Yankee s Despacito ).The Best New Artist category is also majority black this year with SZA, Khalid, and Lil Uzi Vert all gaining nominations. SZA is also this year s most Grammy-nominated woman.Rapper Jay-Z and pop singer Bruno Mars got nods in all three top categories, while rapper/singer Childish Gambino (a.k.a. Donald Glover), rapper Kendrick Lamar, and the coupling of Luis Fonsi & Daddy Yankee got nods in two of the top three categories. Meanwhile, rapper Logic got nominated for his anti-suicide song 1-800-273-8255 for song of the year.Objectively speaking, Jay-Z, Mars, Gambino, Lamar, Fonsi, and Yankee put out some great product this past year, and with any awards show, there are going to be some snubs. However, it appeared that Ed Sheeran, Lady Gaga, Pink, Kelly Clarkson, Kesha, and Miranda Lambert were all looked over from the top categories because of concerns about white supremacy. Instead, Lorde, the 20-year-old New Zealand singer, and Julia Michaels, the 24-year-old singer from Iowa, were the only pop acts to be nominated for the top categories. Washington ExaminerSince rap seems to have surpassed country in popularity (well, at least according to the Grammys), in an effort to address White supremacy , perhaps it s worth taking a look at the black rapper, Snoop Dogg, who shamelessly promotes killing our President and violence against his supporters. Paul Joseph Watson made a brilliant video that exposes how gangster rap increases racism in America. racist 45-year-old rapper Snoop Dogg (**Language warning**):
## 8 CHRISTIAN GROUPS FEARFUL AFTER TARGETED in Fake Hate Groups List Released by CNN CNN published a hate group map and list from the Southern Poverty Law Center that targeted many Christian Organizations. The organizations are fearful for their safety after the bogus hate map with the headline, Here are all the active hate groups where you live. The Southern Poverty Law Center will have blood on their hands if they cause the injury of anyone in these Christian groups. It s bad enough that they labeled these groups as hate groups but now the people in the groups are fearful.Todd Starnes of Townhall reported:The list included among others American Family Association, Family Research Council, Alliance Defending Freedom, Liberty Counsel and Pacific Justice Institute.American Family Association blasted the CNN story calling it a sham news article that could easily incite violence and place AFA employees and supporters in harm s way. Liberty Counsel President Mat Staver demanded an immediate retraction calling CNN s report false, defamatory and dangerous. Liberty Counsel is not a hate group, he said. The false hate label is very damaging to our reputation and is a safety risk to our staff. Liberty Counsel is a Christian ministry, and hates no one. Conservatives and Christians have good reason to be worried.In 2012, Floyd Lee Corkins opened fire inside Family Research Council headquarters in Washington, D.C. A security guard was shot and wounded.The domestic terrorist told police he wanted to kill as many employees as possible to intimidate opponents of same-sex marriage. Corkins brought along Chick-fil-A sandwiches, which he intended to smear on the faces of dead staffers.Corkins told authorities that he picked his target using the Southern Poverty Law Center s so-called hate map. Family Research Council President Tony Perkins appeared on my nationally syndicated radio show Thursday to condemn CNN for using material from an organization that is an attack dog of the Left. They are not a neutral arbiter that is calling balls and strikes. They are on the field playing. They are pushing an agenda and anyone who opposes them they slap a label on them, Perkins told me. They are inciting violence and it needs to stop, he added.READ MORE: TOWNHALL
## 9 China will get better U.S. trade deal if it solves North Korea problem: Trump WASHINGTON (Reuters) - President Donald Trump said on Tuesday he had told China’s President Xi Jinping at a summit last week that Beijing would get a better trade deal with Washington if it helped solve the U.S. problem with North Korea. “I explained to the president of China that a trade deal with the U.S. will be far better for them if they solve the North Korean problem!” Trump, who held talks with Xi in Florida last week, wrote on Twitter. “North Korea is looking for trouble. If China decides to help, that would be great. If not, we will solve the problem without them!” he added in a second note. Persuading China to put pressure on its neighbor and ally North Korea to halt its nuclear weapons and ballistic missile development was a key objective for Trump in his first meeting with Xi. The two leaders agreed to negotiate a 100-day plan aimed at bringing down China’s massive trade surplus with the United States, but the two sides offered few details. China’s ambassador to the United Nations, Liu Jieyi, on Tuesday repeated China’s call for a return to dialogue with North Korea, and when asked about Trump linking a trade deal to China’s help with on North Korea, told Reuters: “We need to look at the situation on the Korean Peninsula as something that we should work together on.” Trump’s linkage of trade and North Korea drew criticism from Senator Charles Schumer, the top Senate Democrat, who has sided with Trump in the past on trade. He called on Trump to stick to his campaign vows to take tough action on Chinese trade abuses. “I think what he’s saying is, if they are tough on North Korea, I’ll go easier on trade,” Schumer said told reporters. “Ask the American people if they like that deal. They won’t.” A senior administration official, who spoke on condition of anonymity, told Reuters China had suggested some areas where trade frictions could be reduced. “We are adding some additional items to that list,” the official said, while declining to give details. Opening China to U.S. beef and U.S. services-sector investment are among the topics in the trade talks, White House spokesman Sean Spicer said on Monday. China agreed last year to end a 13-year ban on U.S. beef, but purchases have yet to resume. “An absolutely minimum starting point is for China to start honoring agreements it’s already committed to,” the U.S. official said.
## 10 Trump Just Committed Obstruction Of Justice By Whining About Comey ‘Leak’ On Twitter Donald Trump broke his Twitter silence over James Comey s Senate testimony on Friday morning by committing an act of obstruction. NOT SMART!During the former FBI Director s testimony on Thursday, Trump watched as Comey slammed him for being a liar who did fire him because he refused to drop the Russia investigation.Comey also admitted that he leaked his memos that covered conversations he had with Trump. He gave the memos to friends and instructed them to give them to the New York Times.And Trump decided to whine about it on Twitter while also declaring that he has been vindicated.Despite so many false statements and lies, total and complete vindication and WOW, Comey is a leaker! Donald J. Trump (@realDonaldTrump) June 9, 2017Except that Trump has not been vindicated at all. He interfered in a federal investigation in order to save his own ass. That s not something innocent people do.But it turns out that Trump may have committed obstruction of justice by attacking Comey on Twitter. And alo because Trump s White House is demanding that the Justice Department investigate Comey for the leaks.According to whistleblower protection attorney Stephen Kohn, Initiating an investigation because you don t like somebody s testimony could be considered obstruction and in the whistleblower context, it s both evidence of retaliation and, under some laws, could be an adverse retaliatory act itself. Indeed, even attacking Comey on Twitter is considered obstruction because, This is a chilling effect on people not to talk about conversations they had with the president that are not classified as a matter of law, Kohn said. That is illegal that is unconstitutional. In short, Trump is intimidating people to remain silent about him and what he says and does, and that s against the law. Not everything the president says or does is classified information. Comey s memos certainly are not classified. Plus, Comey is now a private citizen so the Justice Department has no authority over him. In short, Trump shot himself in the foot when he fired Comey.If Trump forces the Justice Department to go after Comey, it would be a gross abuse of power designed for the sole purpose of retaliating against someone he considers an enemy. Doing such a thing would also scare other people in the government from speaking out. That s obstruction. And Trump should be impeached for it.Twitter even mocked Trump for being such a sore loser.Comey asked the AG that he never be left alone with you, because you would pressure him and then lie. That s obstruction of justice. Sad! Dave Hogg ? (@Stareagle) June 9, 2017Please stop lying. Comey is known for his honesty. You are known, world wide, for being a pathological liar. https://t.co/VQNevWYPmR Jack Schofield (@jackschofield) June 9, 2017It s not leaking if what he was sharing wasn t classified. Comey shared his recollection of conversations Trump had discussed on national TV pic.twitter.com/OqRRS5SEg7 Robert Maguire (@RobertMaguire_) June 9, 2017Guess who else leaked secrets of private Prez meeting? pic.twitter.com/xwwnN4hrVS Melissa Jo Peltier (@MelissaJPeltier) June 9, 2017I believe you re confused, @realDonaldTrump. Maybe this helps. vin di ca tion: the action of clearing someone of blame or suspicion. VoteVets (@votevets) June 9, 2017awww @realDonaldTrump did u get ur phone back? is twitter time out over? a guy that pees on prostitutes should not use leaker as a taunt ROSIE (@Rosie) June 9, 2017Featured Image: Win McNamee/Getty Images
## label
## 1 true
## 2 true
## 3 true
## 4 fake
## 5 fake
## 6 true
## 7 fake
## 8 fake
## 9 true
## 10 fake
We split the data (80% train / 20% test), stratified by label.
df_model <- df_combined |> select(full_text, label)
data_split <- initial_split(df_model, prop = 0.8, strata = label)
train_data <- training(data_split)
test_data <- testing(data_split)
Create a recipe for tokenizing, removing stopwords, filtering vocabulary, and calculating TF-IDF.
text_rec <- recipe(label ~ full_text, data = train_data) |>
step_tokenize(full_text) |>
step_stopwords(full_text) |>
step_tokenfilter(full_text, max_tokens = 5000) |>
step_tfidf(full_text)
Set up a logistic regression model with L1 regularization (lasso) and connect it to the recipe.
log_model <- logistic_reg(penalty = tune(), mixture = 1) |>
set_engine("glmnet") |>
set_mode("classification")
log_wflow <- workflow() |>
add_model(log_model) |>
add_recipe(text_rec)
Use 5-fold cross-validation and create a small grid of penalty values for tuning.
set.seed(321)
folds <- vfold_cv(train_data, v = 5, strata = label)
grid <- tibble(penalty = c(0.01, 0.1))
metrics_to_use <- yardstick::metric_set(
yardstick::accuracy,
yardstick::roc_auc
)
Use tune_grid to evaluate model performance across the grid.
tuned_res <- tune_grid(
log_wflow,
resamples = folds,
grid = grid,
metrics = metrics_to_use
)
## Warning: package 'stopwords' was built under R version 4.4.3
Pick the best model and refit it on the full training set.
best_model <- select_best(tuned_res, metric = "accuracy")
final_wflow <- finalize_workflow(log_wflow, best_model)
final_fit <- fit(final_wflow, data = train_data)
Predict test set labels, calculate metrics, and show confusion matrix.
results <- predict(final_fit, test_data, type = "prob") |>
bind_cols(predict(final_fit, test_data)) |>
bind_cols(test_data)
metrics(results, truth = label, estimate = .pred_class)
## # A tibble: 2 × 3
## .metric .estimator .estimate
## <chr> <chr> <dbl>
## 1 accuracy binary 0.986
## 2 kap binary 0.972
conf_mat(results, truth = label, estimate = .pred_class)
## Truth
## Prediction fake true
## fake 394 5
## true 6 395
Show how accuracy changes across penalty values.
autoplot(tuned_res) +
labs(
title = "Cross-Validation Accuracy vs Penalty",
x = "Penalty (Lambda)",
y = "Accuracy"
) +
theme_minimal()
Visual plot of confusion matrix for easier interpretation.
predict(final_fit, test_data) |>
bind_cols(test_data) |>
conf_mat(truth = label, estimate = .pred_class) |>
autoplot(type = "heatmap") +
labs(title = "Confusion Matrix", subtitle = "Fake vs True") +
theme_minimal()
Show trade-off between true positive and false positive rate.
roc_curve(results, truth = label, .pred_fake) |>
autoplot() +
labs(title = "ROC Curve", subtitle = "Fake News = Positive Class") +
theme_minimal()
Highlight the most informative words by label using TF-IDF.
tidy_tokens <- train_data |>
unnest_tokens(word, full_text) |>
anti_join(stop_words, by = "word") |>
filter(str_length(word) > 2) |>
count(label, word, sort = TRUE) |>
bind_tf_idf(term = word, document = label, n = n)
top_words <- tidy_tokens |>
group_by(label) |>
slice_max(tf_idf, n = 15, with_ties = FALSE) |>
ungroup()
ggplot(top_words, aes(x = tf_idf, y = reorder_within(word, tf_idf, label))) +
geom_col(aes(fill = label), show.legend = FALSE) +
facet_wrap(~ label, scales = "free_y") +
scale_y_reordered() +
labs(title = "Top TF-IDF Words by Label", x = "TF-IDF Score", y = "Word") +
theme_minimal()